Thread classic face questions: there are now T1, T2, T3 three threads, how do you ensure T2 after the implementation of execution in T1, T3 after the implementation of execution in T2? Explain in detail, j-depth understanding of join method

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 method-depth understanding of:

https://blog.csdn.net/u013425438/article/details/80205693

Guess you like

Origin www.cnblogs.com/fyscn/p/11929562.html