Freelance projects

Thursday, May 24, 2012

How to call a method after a delay in Java


Calling a method after delay ... one shot call

private static final ScheduledExecutorService worker = 
  Executors.newSingleThreadScheduledExecutor();
void someMethod() {
  
  Runnable task = new Runnable() {
    public void run() {
      /* Do something… */
    }
  };
  worker.schedule(task, 5, TimeUnit.SECONDS);
  
}
just now found  .... works fine .... :)
source

No comments: