主要考察join的用法
/**
* @author huangke
* @date 2021/7/14 11:21
*/
public class JiaoTiAbc {
public static void main(String[] args) throws InterruptedException {
Thread t1 = new Thread(() -> {
System.out.println("a");
});
Thread t2 = new Thread(() -> {
try {
t1.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("b");
});
Thread t3 = new Thread(() -> {
try {
t2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("c");
});
t1.start();
t2.start();
t3.start();
// 保证主线程在最后执行
t1.join();
t2.join();
t3.join();
System.out.println("执行结束了");
}
}