Java – executorservice, how to know when all threads complete without blocking the main thread?
I have a multi-threaded implementation. I create an executorservice and submit the tasks to be executed. I want to know that the submission time of all threads has been completed without blocking the main thread and UI I have tried executorservice Awaittermination() but it blocks the main thread and UI I searched a lot, but I couldn't seem to find an elegant way to do it I am considering creating another thread to calculate the number of threads completed and start an event when they are all completed, but this is not a good method. I want a better solution!
Solution
Use swingworker to close the thread pool and call awaittermination() This prevents the UI from blocking and calls done() from the event dispatch thread on the swingworker implementation, which you can use to trigger any UI changes you need
If you want to track the running thread through UI update, you can use the worker thread to monitor it in the loop, call publish () with parameters, and then pass the parameters to the process () implementation on EDT