线程执行过程中添加新线程

package com.aaa.thread.Test;

public class TestTwo implements Runnable {
    @Override
    public void run() {
        for (int i=0;i<10;i++){
            System.out.println(Thread.currentThread().getName() + "	" + i);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        TestTwo testTwo = new TestTwo();
        Thread t = new Thread(testTwo,"One");
        t.start();
        for (int i=1;i<11;i++){
            System.out.println(Thread.currentThread().getName());
            if (i==3){
                t.join();
            }
        }
    }
}

  

原文地址:https://www.cnblogs.com/fanqiexin/p/11118764.html