membersound
membersound

Reputation: 86925

How to delay a ScheduledExecutorService?

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

Answers (1)

Boris the Spider
Boris the Spider

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

Related Questions