public class Test2 {
public static void main(String[] args) throws InterruptedException {
long start=System.currentTimeMillis();
final CountDownLatch countDownLatch=
new CountDownLatch(4);
for(int i=0;i<4;i++){
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("执行完一个线程减1");
countDownLatch.countDown();
}
}).start();
}
countDownLatch.await();//等待直到4个线程执行完成,为0时才向下执行
long end=System.currentTimeMillis();
System.out.println("耗时:"+(end-start));
}
}
CountDownLatch
最新推荐文章于 2024-03-17 21:20:55 发布