考察join
/** * 现有T1、T2、T3三个线程,你怎样保证T2在T1执行完成之后执行,T3在T2执行完后执行? * @author user * */ public class Test3 { public static void main(String[] args) throws InterruptedException { Thread T1 = new Thread(new T1()); Thread T2 = new Thread(new T2()); Thread T3 = new Thread(new T3()); T1.start(); T1.join(); T2.start(); T2.join(); T3.start(); T3.join(); } } class T1 implements Runnable{ @Override public void run() { System.out.println(Thread.currentThread()+"T1"); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } } } class T2 implements Runnable{ @Override public void run() { System.out.println(Thread.currentThread()+"T2"); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } } } class T3 implements Runnable{ @Override public void run() { System.out.println(Thread.currentThread()+"T3"); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } } }