ScheduledExecutorService executor=Executors.newScheduledThreadPool(1);
System.out.printf("Main: Starting at: %s\n",new Date());
// Create a new task and sends it to the executor. It will start with a delay of 1 second and then
// it will execute every two seconds
Task task=new Task("Task");
ScheduledFuture<?> result=executor.scheduleAtFixedRate(task, 1, 2, TimeUnit.SECONDS);
// Controlling the execution of tasks
for (int i=0; i<10; i++){
System.out.printf("Main: Delay: %d\n",result.getDelay(TimeUnit.MILLISECONDS));