wait until all threads finish their work in java

后端 未结 16 1882
情深已故
情深已故 2020-11-22 14:10

I\'m writing an application that has 5 threads that get some information from web simultaneously and fill 5 different fields in a buffer class.
I need to validate buffer

16条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 15:05

    Use this in your main thread: while(!executor.isTerminated()); Put this line of code after starting all the threads from executor service. This will only start the main thread after all the threads started by executors are finished. Make sure to call executor.shutdown(); before the above loop.

提交回复
热议问题