代码演示
// 测试join方法,想象为插队
public class TestJoin 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 {
// vip线程 启动
TestJoin testJoin = new TestJoin();
Thread thread = new Thread(testJoin);
for (int i = 0; i < 1000; i++) {
if (i==200){
thread.start();
// vip线程插队
thread.join();
}
// 执行主线程
System.out.println("main"+i);
}
}
}
代码截图