1 package com.atguigu.boot.com.atguigu; 2 3 import com.sun.org.apache.bcel.internal.generic.NEW; 4 5 import java.util.concurrent.CountDownLatch; 6 7 public class CountDownLatchDemo { 8 private static final int CONSTANT_NUM=6; 9 10 public static void main(String[] args) throws InterruptedException { 11 CountDownLatch count=new CountDownLatch(CONSTANT_NUM); 12 for (int i = 1; i <7 ; i++) { 13 new Thread(()->{ 14 System.out.println(Thread.currentThread().getName()+"\t 国,被灭"); 15 count.countDown(); 16 },CountryEnum.forEach_CountryEnum(i).getMess()).start(); 17 } 18 count.await(); 19 System.out.println(Thread.currentThread().getName()+"\t ********秦帝国,统一华夏"); 20 } 21 22 private static void closeDoor() throws InterruptedException { 23 CountDownLatch count=new CountDownLatch(CONSTANT_NUM); 24 for (int i = 0; i <6 ; i++) { 25 new Thread(()->{ 26 System.out.println(Thread.currentThread().getName()+"\t 上完自习,离开教室"); 27 count.countDown(); 28 },String.valueOf(i)).start(); 29 } 30 count.await(); 31 System.out.println(Thread.currentThread().getName()+"\t ********班长最后关门走人"); 32 } 33 }