Scheduling Tasks to Execute After a Given Delay or Periodically in Java

ScheduledExecutorService scheduler
                            = Executors.newSingleThreadScheduledExecutor();
 
        Runnable task = new Runnable() {
            public void run() {
                System.out.println("Hi!");
            }
        };
 
        int delay = 5;
        scheduler.schedule(task, delay, TimeUnit.SECONDS);
        scheduler.shutdown();

References
http://www.codejava.net/java-core/concurrency/java-concurrency-scheduling-tasks-to-execute-after-a-given-delay-or-periodically

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.