import java.util.Date; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; public class ExecutorTest8 { public ExecutorTest8() { ScheduledExecutorService e = Executors.newScheduledThreadPool(1); e.schedule(new RunnableTask("Task"), 2000, TimeUnit.MILLISECONDS); System.out.println("Task is called at " + new Date()); e.shutdown(); } class RunnableTask implements Runnable { private String name; public RunnableTask(String name) { this.name = name; } public void run() { System.out.println(name + " starts at " + new Date()); try { Thread.sleep(1000L); } catch (InterruptedException ex) { System.out.println(name + " is Canceled"); return; } System.out.println(name + " is done at " + new Date()); } } public static void main(String[] args) { new ExecutorTest8(); } }