如何等待多个线程完成?
2022-08-31 08:58:55
有什么方法可以简单地等待所有线程进程完成?例如,假设我有:
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()