线程插队Join

public class test04 {

public static void main(String[] args) throws InterruptedException {
Q q = new Q();
Thread thread = new Thread(q);
for (int i = 0; i < 10; i++) {
Thread.sleep(1000);
System.out.println("hi");
if (i == 4) {
thread.start();
thread.join();

}

}
System.out.println("主线程结束");

}

}


class Q implements Runnable {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println("hellow");
}
System.out.println("子线程结束");
}
}
posted @ 2023-04-06 14:11  霍叔  阅读(24)  评论(0)    收藏  举报