package com.example.demo.thread;
/**
* @projectName: demo
* @package: com.example.demo.thread
* @className: TestJoin
* @author:
* @description:
* @date: 2021/11/26 18:40
*/
public class TestJoin {
public static void main(String[] args) throws InterruptedException {
MyJoin myJoin = new MyJoin();
Thread thread = new Thread(myJoin);
thread.start();
for (int i = 0; i < 1000; i++) {
if (i == 100) {
thread.join();
}
System.out.println("主線程" + i + "次");
}
}
}
class MyJoin implements Runnable {
@Override
public void run() {
for (int i = 0; i < 100; i++) {
System.out.println("jion線程" + i + "次");
}
}
}
最開始主線程和Myjoin全在執(zhí)行
滿足條件后優(yōu)先執(zhí)行MyJoin
MyJoin執(zhí)行完成后再執(zhí)行主線程