线程经典面试题:现在有T1、T2、T3三个线程,你怎样保证T2在T1执行完后执行,T3在T2执行完后执行?详细讲解,j深入了解join方法
package com.threadDemo; public class JoinTestSync { public static void main(String[] args) throws InterruptedException { // TODO Auto-generated method stub ThreadJoinTest1 t1 = new ThreadJoinTest1("今天"); ThreadJoinTest1 t2 = new ThreadJoinTest1("明天"); ThreadJoinTest1 t3 = new ThreadJoinTest1("后天"); /* * 通过join方法来确保t1、t2、t3的执行顺序 * */ t1.start(); t1.join(); t2.start(); t2.join(); t3.start(); t3.join(); } } class ThreadJoinTest1 extends Thread{ public ThreadJoinTest1(String name){ super(name); } @Override public void run(){ for(int i=0;i<5;i++){ System.out.println(this.getName() + ":" + i); } }
join方法深入理解:
https://blog.csdn.net/u013425438/article/details/80205693