I scheduled a recurring task. Now I want the main thread to wait for the ScheduledExecutorService
to complete its first execution. How can i accomplish this?
public void test1(){
refreshFunction(); /* This should block until task has executed once. */
/* Continue with main thread. */
...
}
public void refreshFunction() {
try {
scheduledExecutorService = Executors.newScheduledThreadPool(1);
scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
loadInfo();
}
}, 1, 5, TimeUnit.MINUTES);
logger.info(" : Completed refreshing information : "
+ new Timestamp(System.currentTimeMillis()));
} catch (Exception ex) {
ex.printStackTrace();
}
}