【发布时间】:2013-04-04 02:06:26
【问题描述】:
在这段代码中,两个join和break是什么意思? t1.join() 导致 t2 停止直到 t1 终止?
Thread t1 = new Thread(new EventThread("e1"));
t1.start();
Thread t2 = new Thread(new EventThread("e2"));
t2.start();
while (true) {
try {
t1.join();
t2.join();
break;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
【问题讨论】:
-
既然会阻塞等待线程终止,那为什么要用while循环呢?
-
@MahdiElMasaoudi 我想,即使线程被中断也要继续等待?可能不是这样做的好方法
-
如果有帮助记得在这里接受答案。
-
如前所述,您不需要
while(true)来调用join方法。
标签: java multithreading