package com.moxi.mougblog.base.util;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
public class CountDownLatchUtils {
public static void main(String[] args) {
int threadNum = 10;
CountDownLatch count = new CountDownLatch(threadNum);
for (int i = 0;i < threadNum;i++){
int finalI = i;
Thread thread = new Thread(){
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+"结束了");
count.countDown();
}
};
thread.start();
}
try {
count.await();
System.out.println(Thread.currentThread().getName()+"开始了");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
countDownLatch
最新推荐文章于 2022-10-09 20:46:38 发布