多线程工具类 |
1、CountDownLatch (倒计时锁存器)
一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待
代码示例:使一个线程等待其他线程各自执行完毕后再执行
public class Demo{
public static void main(String[] args) throws InterruptedException{
CountDownLatch cdl = new CountDownLatch(3);
for(int i = 1;i<=3;i++){
new Thread(()->{
System.out.println(Thread.currentThread().getName()+"出门");
cdl.countDown(