公众号:架构师与哈苏
关注公众号进入it交流群! 公众号:架构师与哈苏 不定时都会推送一些实用的干货。。。
/**
 * 控制线程的执行循序 T1 -> T2 -> T3
 * join实现
 */
public static void join(){
    Thread t1 = new Thread(() -> {
        System.out.println("hello my is T1!");
    });

    Thread t2 = new Thread(() -> {
        try {
            t1.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("hello my is T2!");
    });

    Thread t3 = new Thread(() -> {
        try {
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("hello my is T3!");
    });

    t3.start();
    t2.start();
    t1.start();

}
posted on 2021-08-05 11:34  公众号/架构师与哈苏  阅读(17)  评论(0编辑  收藏  举报