5

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.

1

2 Answers 2

7

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

Sign up to request clarification or add additional context in comments.

1 Comment

I have a flacky test that may be related to using this. Reading the documenttion states that this number is an aproximation: "Returns the approximate number of threads that are actively executing tasks".
1

You can use ThreadPoolExecutor.getCompletedTaskCount()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.