Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何检查提交的所有任务是否ThreadPoolExecutor已完成?
ThreadPoolExecutor
可以从之前提交的任务中添加新任务,所以我不能调用shutdown后面的awaitTerminationnor invokeAll,因为它会忽略这些新任务。
shutdown
awaitTermination
invokeAll
yourThreadPoolExecutor.getActiveCount();完成所有任务后将返回 0。
yourThreadPoolExecutor.getActiveCount();
您可以使用 ThreadPoolExecutor.getCompletedTaskCount()