Wait until child threads completed : Java

前端 未结 6 761
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 04:08

Problem description : -

Step 1: Take input FILE_NAME from user at main thread.

Step 2: Perform 10 operations on

6条回答
  •  广开言路
    2020-11-30 04:49

    Check if all child threads are dead, every n seconds. Simple, yet effective method:

            boolean allDead=false;
            while(! allDead){
                allDead=true;
                for (int t = 0; t < threadCount; t++)
                    if(threads[t].isAlive())    allDead=false;
                Thread.sleep(2000);
    
            }
    

提交回复
热议问题