62,620
社区成员
发帖
与我相关
我的任务
分享 temp = new mthread(Integer.MAX_VALUE/50);
temp.setName("临时2");
temp.start();
temp.waitother(mt);
mt = temp;
package dadsa;
public class ThreadDemo extends Thread{
private mthread mt;
public static void main(String[] args) {
ThreadDemo td = new ThreadDemo();
td.test();
}
private void test(){
mt = new mthread(Integer.MAX_VALUE/2);
mt.setName("mt");
mthread temp = new mthread(Integer.MAX_VALUE/5);
temp.setName("临时1");
mt.start();
temp.start();
temp.waitother(mt);
mt = temp;
temp = new mthread(Integer.MAX_VALUE/50);
temp.setName("临时2");
temp.start();
temp.waitother(mt);
mt = temp;
try {
mt.join();
System.exit(0);
} catch (InterruptedException e) {
e.printStackTrace();
}
//下面的代码未执行
temp = new mthread(Integer.MAX_VALUE/2);
temp.setName("临时3");
temp.start();
}
class mthread extends Thread{
private int max;
public mthread(int max){
this.max = max;
}
public void run(){
int s = 0;
for(int i=0;i<max;i++){
// if(wait&&waitit.isAlive())
// try {
// waitit.join();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
s = s + i;
}
System.err.println(this.getName()+"执行完了");
}
public void waitother(mthread mtd){
try {
mtd.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}