wait until all threads finish their work in java

后端 未结 16 2158
情深已故
情深已故 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

    I created a small helper method to wait for a few Threads to finish:

    public static void waitForThreadsToFinish(Thread... threads) {
            try {
                for (Thread thread : threads) {
                    thread.join();
                }
            }
            catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    

提交回复
热议问题