Wednesday, 26 June 2013

Schedule a Method to run later

If you do not want to run a method in the normal application process flow, you can use ScheduledExecutorService to run it later. This sample code executes the "myFunction" 5 Seconds later.

final ScheduledExecutorService exec = Executors.newScheduledThreadPool(1);
exec.schedule(new Runnable() {
@Override
public void run() {
System.out.println("=================> Running");
myFunction();
}
}, 5, TimeUnit.SECONDS);
view raw gistfile1.java hosted with ❤ by GitHub

No comments:

Post a Comment