比如我建了2个线程
Thread t1=new Thread();
Thread t2=new Thread();
建立的时候这2个线程是无关的,那么怎么才能做到等一个结束时,立马让另一个也结束?
(这里只是用2举例,实际是好多线程)
谢谢
Thread t1=new Thread();
Thread t2=new Thread();
建立的时候这2个线程是无关的,那么怎么才能做到等一个结束时,立马让另一个也结束?
(这里只是用2举例,实际是好多线程)
谢谢
如果更精确点,在while中几个点判断,如果不满足,break就行了,这里不需要stop或者interrupt
class Runner4 implements Runnable{
private boolean flag = true;
int i ;
public void run(){
while(flag)
System.out.println(" " + i ++);
}
public void shutdown(){
flag = false;
}
}public class TestThread4 {
public static void main(String[] args) {
Runner4 r = new Runner4();
Thread t = new Thread(r);
t.start();
for(int i = 0; i < 100000; i++){
if(i % 10000 == 0 && i != 0)
System.out.println("in thread main i = " + i);
}
System.out.println("Thread Main is over");
r.shutdown();
}}
□ □
■ 忍以明志 勤以致远 ■
□ □
■□■□■□■□■□■□■□■
基于CSDN论坛提供的插件扩展功能,自己做了个签名档工具,分享给大家,欢迎技术交流 :)