How to wait for a ThreadPoolExecutor to finish?
myThreadPoolExecutor.shutdown();
while (!myThreadPoolExecutor.isTerminated()) {
//do thing
}
Alternative way:
myThreadPoolExecutor.shutdown();
if (!myThreadPoolExecutor.awaitTermination(1000, TimeUnit.SECONDS))
System.err.println("Threads didn't finish in 1000 seconds!");
}
0 comments:
Post a Comment