14 线程强制执行

zhanjianhai / 2023-09-06 / 原文

package ThreadDemo;

// join 被插队
public class Test14_Join implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 200; i++) {
            System.out.println("子线程开始插队->"+i);
        }
    }

    public static void main(String[] args) throws InterruptedException{
        Test14_Join test14Join = new Test14_Join();
        Thread thread = new Thread(test14Join);   // 静态代理模式
        thread.start();

        // 主线程
        for (int i = 0; i < 50; i++) {
            if (i==10){
              //   Thread.join() // 被插队且等子线程完成后才能继续执行, 不知为何,没有这个方法  
            }
            System.out.println("主线程->"+i);

        }


    }
}