package com.kpmg.thread; public class TestJoin { public static void main(String[] args) throws InterruptedException { Thread t1 = new Thread(()->{ for (int i = 0; i < 100; i++) { System.out.println("t1 start"); } }); Thread t2 = new Thread(()->{ try { t1.join(); } catch (InterruptedException e) { e.printStackTrace(); } for (int i = 0; i < 100; i++) { System.out.println("t2 start"); } }); Thread t3 = new Thread(()->{ try { t2.join(); } catch (InterruptedException e) { e.printStackTrace(); } for (int i = 0; i < 100; i++) { System.out.println("t3 start"); } }); t1.start(); t2.start(); t3.start(); t3.join(); System.out.println("主线程运行结束"); } }
原文:https://www.cnblogs.com/johnzhao/p/15024166.html