筆記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);
        }
    }
}
相關文章
相關標籤/搜索