如何等待多个线程完成?
简单地等待所有线程进程完成的方法是什么?例如,假设我有:
public class DoSomethingInAThread implements Runnable{
public static void main(String[] args) {
for (int n=0; n<1000; n++) {
Thread t = new Thread(new DoSomethingInAThread());
t.start();
}
// wait for all threads' run() methods to complete before continuing
}
public void run() {
// do something here
}}我如何改变这一点,以便main()方法在注释处暂停,直到所有线程的run()方法都退出?谢谢!
阿波罗的战车
MMTTMM
神不在的星期二
慕虎7371278
随时随地看视频慕课网APP
相关分类