public class TestMethod {
/**
* @param args
*/
public static void main(String[] args) {
List<Thread> list = new ArrayList<Thread>();
for(int i =0;i<100;i++){
Out out = new Out();
Thread t = new Thread(out);
list.add(t);
t.start();
}
for(int i = 0;i<list.size();i++){
Thread t = list.get(i);
try {
t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("all over!");
}
}
class Out implements Runnable{
public void run() {
System.out.println(Thread.currentThread().getName()+" begin");
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
JAVA主线程等待子线程全部结束
最新推荐文章于 2024-07-27 21:05:24 发布