ExecutorService awaitTermination gets stuck ExecutorService awaitTermination gets stuck multithreading multithreading

ExecutorService awaitTermination gets stuck


As Peter pointed out, shutdown() must be called first.

source: javadoc


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.