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

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() + "\t" + 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();
            }
        }
    }
}

  

posted @ 2019-07-02 10:03  织式  阅读(313)  评论(0编辑  收藏  举报