线程强制执行-join
线程强制执行-join
强制执行就是插队
join合并线程,待次线程执行完成后,再执行其他线程,其他线程阻塞
代码
package com.example.multi_thread;
public class TestJoin implements Runnable {
@Override
public void run() {
for (int i = 0; i < 20; i++) {
System.out.println("I'm vip " + i);
}
}
public static void main(String[] args) throws InterruptedException {
TestJoin testJoin = new TestJoin();
Thread thread = new Thread(testJoin);
thread.start();
for (int i = 0; i < 10; i++) {
System.out.println(i);
if (i == 5) {
thread.join();
}
}
}
}

浙公网安备 33010602011771号