13,100
社区成员
发帖
与我相关
我的任务
分享
Thread t = new Thread(){
public void run(){
Thread th1 = new Thread();
Thread th2 = new Thread();
Thread th3 = new Thread();
Thread th4 = new Thread();
//这四个线程分别运行5秒
try {
th1.start();
th1.join();
th2.start();
th2.join();
th3.start();
th3.join();
th4.start();
th4.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
t.start();
Thread t = new Thread(){
public void run(){
Thread th1 = new Thread();
Thread th2 = new Thread();
Thread th3 = new Thread();
Thread th4 = new Thread();
//这四个线程分别运行5秒
try {
if(!stop){//设置一个boolean变量 现在也不去调用interrupt函数了 这样可行吗?
th1.start();
th1.join();
}
if(!stop){
th2.start();
th2.join();
}
if(!stop){
th3.start();
th3.join();
}
if(!stop){
th4.start();
th4.join();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
t.start();