public class test04 {标签:Join,Thread,插队,System,线程,println,new,public,out From: https://www.cnblogs.com/hhx070911/p/17292595.html
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("子线程结束");
}
}