Reputation: 86925
I have a ScheduledExecutorService
that executes a task periodically:
executor.scheduleWithFixedDelay(new Runnable() {
On a specific event, I want to reset or delay time for the schedule. How can or should this be done?
Upvotes: 1
Views: 123
Reputation: 61198
You need to keep a reference to the Future<?>
returned by that method.
Future<?> taskHandle = scheduledExecutorService.scheduleAtFixedRate
Then call cancel
on it and schedule it again at a different rate.
taskHandle.cancel(false);
taskHandle = scheduledExecutorService.scheduleAtFixedRate
Upvotes: 2