ExecutorService awaitTermination gets stuck
You could also use ExecutorService#invokeAll. It blocks until all tasks are done or the timeout is reached. It's a little cleaner than using shutdown
, if your ExecutorService contains other tasks as well especially scheduled tasks. These would also be affected by a call to shutdown
.