I am using ExecutorService
in Java web server application for executing some computational tasks in parallel style and then calling shutdown()
with awaitTermination()
to wait for all tasks to be done. Whole computation can sometimes take dozens of minutes.
The thing is awaitTermination()
method blocks the main thread until timeout elapsed (or interrupted) but I just want to start the tasks and immediatedly respond to client and after competition of all tasks shutdown the service (following conventions to always close the thread pool).
So my question, is there a way how I can be notified when all tasks are done so I could call the shutdown()
method? Listener or something..
Thanks!