package com.Java;
//Join 线程插队 必须执行完再执行其他线程
public class TestJoin implements Runnable {
@Override
public void run() {
for (int i = 0; i < 500; i++) {
System.out.println("我是vip" + i);
}
}
public static void main(String[] args) throws InterruptedException {
TestJoin tj = new TestJoin();
Thread thread = new Thread(tj);
thread.start();
for (int i = 0; i < 1000; i++) {
if (i == 300) {
thread.join();//插队 必须执行完
}
System.out.println("主线程" + i);
}
}
}
Join线程强制执行
![](https://img2024.cnblogs.com/blog/35695/202502/35695-20250207193705881-1356327967.jpg)