Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking whether all tasks in ThreadPoolExecutor are completed

How can I check whether all tasks submitted to ThreadPoolExecutor are completed?

New tasks can be added from previously submitted tasks, so I can't call shutdown followed by awaitTermination nor invokeAll, as it will ignore these new tasks.

like image 528
Sebastian Nowak Avatar asked May 14 '13 21:05

Sebastian Nowak


2 Answers

yourThreadPoolExecutor.getActiveCount(); will return 0 when all tasks have completed.

like image 192
assylias Avatar answered Sep 20 '22 12:09

assylias


You can use ThreadPoolExecutor.getCompletedTaskCount()

like image 42
Evgeniy Dorofeev Avatar answered Sep 23 '22 12:09

Evgeniy Dorofeev