简单地等待所有线程进程完成的方法是什么?例如,假设我有:
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
}
}
Run Code Online (Sandbox Code Playgroud)
我如何改变这一点,以便main()方法在注释处暂停,直到所有线程的run()方法都退出?谢谢!