线程中join的用法

/**
 * 有三个线程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();
    }
}

猜你喜欢

转载自blog.csdn.net/zxk1995/article/details/80043719