Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA - Cancel the ThreadPoolExecutor running tasks

What I need is a method similar to shutdownNow, but, be able to submit new tasks after that. My ThreadPoolExecutor will be accepting a random number of tasks during my program execution.

like image 693
rgomesf Avatar asked May 13 '10 17:05

rgomesf


1 Answers

You can grab the Future of each submission, store that Future in a collection, then when you want to cancel the tasks, invoke future.cancel() of all queued tasks.

With this solution the Exectuor is still running and any running tasks are cancelled or will not run if they are queued.

like image 188
John Vint Avatar answered Nov 01 '22 15:11

John Vint