package com.xzx.gc; public class Main { public static void main(String[] args) { WorkThread workThread1 = new WorkThread(); WorkThread workThread2 = new WorkThread(); workThread1.start(); workThread2.start(); //阻塞Main线程,执行子线程workThread1和workThread2,完毕后继续执行后续的逻辑 try { System.out.println("1"+Thread.currentThread().getName()); workThread1.join(); System.out.println("2"+Thread.currentThread().getName()); workThread2.join(); System.out.println("3"+Thread.currentThread().getName()); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("run next process."); } } class WorkThread extends Thread { @Override public void run() { try { System.out.println(getName() + "run start."); //模拟完成子任务执行的时间 sleep(1000); System.out.println(getName() + "run finished."); } catch (InterruptedException e) { e.printStackTrace(); } } }