1 join() 当前线程中出现 thread1.join() 会先执行完thread1 然后再执行当前线程
public static void main(String[] args) { final Thread threadN = new Thread(new Runnable() { @Override public void run() { System.out.println("产品经理正在规划新需求..."); } }); final Thread thread2 = new Thread(new Runnable() { @Override public void run() { try { thread1.join(); System.out.println("开发人员开发新需求功能"); } catch (InterruptedException e) { e.printStackTrace(); } } }); final Thread thread3 = new Thread(new Runnable() { @Override public void run() { try { thread2.join(); System.out.println("测试人员测试新功能"); } catch (InterruptedException e) { e.printStackTrace(); } } }); try { System.out.println("产品经理来上班了"); System.out.println("测试人员来上班了"); System.out.println("开发人员来上班了"); thread1.start(); //在父进程调用子进程的join()方法后,父进程需要等待子进程运行完再继续运行。 System.out.println("开发人员和测试人员休息会..."); thread1.join(); System.out.println("产品经理新需求规划完成!"); thread2.start(); System.out.println("测试人员休息会..."); thread2.join(); thread3.start(); } catch (InterruptedException e) { e.printStackTrace(); } }