线程强制执行(插队)

package com.qiliang.dmeo09_线程强制执行;

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


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

        // 主线程
        for (int i = 0; i < 500; i++) {
            if(i==20){
                thread.join();// 插队 ,这个线程走完了其他线程才可以走
            }
            System.out.println("main"+i);
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/liqiliang1437/p/12794779.html