线程强制执行
-
join 合并线程,待此线程执行完成后,再执行其它线程,其它线程阻塞
-
可以想象成插队
public class TestJoin implements Runnable{
public static void main(String[] args) throws InterruptedException {
//启动我们的线程
TestJoin testJoin = new TestJoin();
Thread thread = new Thread(testJoin);
thread.start();
//主线程
for (int i = 1; i <= 15; i++) {
if (i==5){
thread.join();//插队,main线程阻塞
}
System.out.println("main方法"+i);
}
}
@Override
public void run() {
for (int i = 1; i <= 8; i++) {
System.out.println("线程vip来了"+i);
}
}
}