Let\'s assume we have the following code:
List> runningTasks;
ExecutorService executor;
...
void executeTask(Runnable task){
runningTas
Future
.If you use ScheduledFuture
then you may face memory leak issue as ScheduledFuture.cancel()
or Future.cancel()
in general does not notify its Executor
that it has been cancelled and it stays in the Queue until its time for execution has arrived. It's not a big deal for simple Futures but can be a big problem for ScheduledFutures
. It can stay there for seconds, minutes, hours, days, weeks, years or almost indefinitely depending on the delays it has been scheduled with.
For more details with example of memory leak situation and its solution see my other answer.