62,614
社区成员
发帖
与我相关
我的任务
分享
package com.ma.third.join;
public class Thread1 extends Thread {
@Override
public void run() {
super.run();
synchronized(this){
try {
System.out.println("t1 begin");
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("t1 end");
}
}
}
package com.ma.third.join;
public class MyMain1 {
public static void main(String[] args) {
Thread1 t1 = new Thread1();
t1.setName("t1");
t1.start();
try {
t1.join(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("main end");
}
}