ScheduledThreadPoolExecutor retains cancelled tasks until they would be due to avoid clean up overhead.
As we cancel scheduled tasks regularly, we want to get rid of cancelled tasks even with the penalty of the clean up overhead otherwise we might have an excessive memory usage when having many tasks scheduled in the distant future which are then cancelled.
The retention policy of ScheduledThreadPoolExecutor is configured via setRemoveOnCancelPolicy(boolean).
ScheduledThreadPoolExecutor
retains cancelled tasks until they would be due to avoid clean up overhead. As we cancel scheduled tasks regularly, we want to get rid of cancelled tasks even with the penalty of the clean up overhead otherwise we might have an excessive memory usage when having many tasks scheduled in the distant future which are then cancelled. The retention policy ofScheduledThreadPoolExecutor
is configured viasetRemoveOnCancelPolicy(boolean)
.