I have it:
ScheduledExecutorService scheduledThreadPool = Executors .newScheduledThreadPool(5);
Then I run the task as follows:
scheduledThreadPool.scheduleAtFixedRate(runnable, 0, seconds, TimeUnit.SECONDS);
I keep a reference to the future as follows:
ScheduledFuture<?> scheduledFuture = scheduledThreadPool.scheduleAtFixedRate(runnable, 0, seconds, TimeUnit.SECONDS);
I want to be able to undo and delete the future
scheduledFuture.cancel(true);
However, this SO answer notes that canceling does not delete it, and adding new tasks will end with many tasks that cannot be GCed.
stack overflow
They mention something about setRemoveOnCancelPolicy , however this scheduledThreadPool does not have such a method. What should I do?
java multithreading concurrency
JK Apr 20 '16 at 15:08 2016-04-20 15:08
source share