JAVA-JOIN

插队

package com.alipay.sofa.web.test.base;

public class ThreadJoinTest implements Runnable {
    //线程体
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println("线程体"+i);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        //启动线程
        ThreadJoinTest tjt = new ThreadJoinTest();
        Thread thread = new Thread(tjt);
        thread.start();

        for (int i = 0; i < 1000; i++) {
            System.out.println("主线程"+i);
            if (i == 200){
                thread.join();
            }
        }
    }

}
原文地址:https://www.cnblogs.com/xuzhongyin/p/13572942.html