I am following up an interesting question on so, on usage of ScheduledThreadPoolExecutor for some repeating task.
Scheduling this object returns a ScheduledFuture object which one can use to cancel the next run of the task.
One thing to note here is the task itself is completely decoupled from the schedule--
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1);
ScheduledFuture nextSchedule =
executor.schedule(task, 60000, TimeUnit.MILLISECONDS);
where-
SomeTask task = new SomeTask();
So the task itself is not aware of the schedule. Please enlighten if there is a way to get the task to cancel and create a new schedule for itself.
Thanks