package com.lyon.juc; import java.util.concurrent.CountDownLatch; //减法计数器 public class CountDownLatchDemo { public static void main(String[] args) throws InterruptedException { //总数是5 CountDownLatch countDownLatch = new CountDownLatch(5); for (int i = 1; i <= 5; i++) { new Thread(()->{ System.out.println(Thread.currentThread().getName()+"go out"); countDownLatch.countDown();//数量减1 },String.valueOf(i)).start(); } countDownLatch.await();//等待计数器归零,然后在向下执行 System.out.println("Close door"); } }
多线程之减法计数器
最新推荐文章于 2022-09-13 22:00:24 发布