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全在执行
满足条件后优先执行MyJoin
MyJoin执行完成后再执行主线程
网友评论