文章目录
Thread.join()方法
编码实现:
/**
* @Author chenwenlin
* @Date 2023-07-20 22:51
*/
public class JoinTest {
public static void main(String[] args) throws InterruptedException {
Thread t1 = new Thread(() -> {
try {
TimeUnit.SECONDS.sleep(10);
} catch (InterruptedException exception) {
exception.printStackTrace();
}
System.out.println("T1 执行完成.... ");
}, "t1");
Thread t2 = new Thread(() -> {
try {
TimeUnit.SECONDS.sleep(10);
} catch (InterruptedException exception) {
exception.printStackTrace();
}
System.out.println("T2 执行完成.... ");
}, "t2");
Thread t3 = new Thread(() -> {
try {
TimeUnit.SECONDS.sleep(10);
} catch (InterruptedException exception) {
exception.printStackTrace();
}
System.out.println("T3 执行完成.... ");
}, "t3");
t1.start();
t1.join();
t2.start();
t2.join();
t3.start();
}
}