I have a scheduled task (running in fixed delay execution), started like this:
executoreService.scheduleWithFixedDelay(repeatingThread, 0, numOfSeconds, TimeUnit.SECONDS);
On every start of cycle, I check for a change in a settings file, and then I want to restart the task. The settings file also contains length of the interval (numOfSeconds
in the above code).
Currently, I am using the following code to restart the task:
executoreService.shutdownNow();
try {
while(!executoreService.awaitTermination(5, TimeUnit.SECONDS)){
logger.debug("awaiting termintation");
}
} catch (InterruptedException e) {
logger.debug("interrupted, continuing", e);
}
// initialize startup parameters
init();
// start the main scheduled timer
executoreService.scheduleWithFixedDelay(repeatingThread, 0, numOfSeconds, TimeUnit.SECONDS);
I'm not sure about these API calls. What is the recommended way to restart the task (possibly with a new delay)?