笔记20200520:多线程【线程强制执行_join】

package com.chengguo.线程;

/**
 * 测试 join方法【想象为插队】
 */
public class Demo_20200518004_Join implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            System.out.println("VIP线程……" + i);
        }

    }

    public static void main(String[] args) throws InterruptedException {
        //创建对象
        Demo_20200518004_Join dj1 = new Demo_20200518004_Join();
        //创建一个线程对象
        Thread thread = new Thread(dj1);
        thread.start();

        //主线程
        for (int i = 0; i < 500; i++) {
            if (i == 5) {
                thread.join();
            }
            System.out.println("main--->" + i);
        }
    }
}

 

posted @ 2020-06-03 23:40  忧桑の民工  阅读(125)  评论(0编辑  收藏  举报