import lombok.SneakyThrows;
import java.util.concurrent.TimeUnit;
public class T {
@SneakyThrows
public static void main(String[] args) {
Object o = new Object();
Thread thread1 = new Thread(() -> {
try {
System.out.println(Thread.currentThread().getName() + "运行");
TimeUnit.SECONDS.sleep(2);
System.out.println(Thread.currentThread().getName() + "运行 over");
} catch (Exception e) {
e.printStackTrace();
}
}, "线程1");
Thread thread2 = new Thread(() -> {
try {
thread1.join();
System.out.println(Thread.currentThread().getName() + "运行");
TimeUnit.SECONDS.sleep(3);
System.out.println(Thread.currentThread().getName() + "运行over");
} catch (Exception ex) {
}
}, "线程2");
Thread thread3 = new Thread(() -> {
try {
thread2.join();
System.out.println(Thread.currentThread().getName() + "运行");
} catch (Exception ex) {
}
}, "线程3");
thread1.start();
thread2.start();
thread3.start();
}
}
标签:顺序,join,Thread,currentThread,getName,System,线程,out
From: https://www.cnblogs.com/goodluckxiaotuanzi/p/18358470