5.4、线程插队
2021-12-08 本文已影响0人
金石_832e
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 + "次");
}
}
}
![](https://img.haomeiwen.com/i16435586/20e3cc3da9ae49c1.png)
![](https://img.haomeiwen.com/i16435586/af87010cc9161457.png)
![](https://img.haomeiwen.com/i16435586/461d35ea272c0440.png)