The usage of join in thread

/**
 * 有三个线程t1,t2,t3;怎么保证让t1走完后走t2,t2走完后走t3
 */
public class JoinTest extends Thread{

    @Override
    public void run() {
        for(int i=0;i<30;i++) {
            System.out.println(this.getName()+"---"+i);
        }
    }
    
    public static void main(String[] args) throws InterruptedException {
        JoinTest t1 = new JoinTest();
        t1.setName("t1");
        t1.start();
        t1.join();
        JoinTest t2 = new JoinTest();
        t2.setName("t2");
        t2.start();
        t2.join();
        JoinTest t3 = new JoinTest();
        t3.setName("t3");
        t3.start();
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324675516&siteId=291194637