import java.util.concurrent.CountDownLatch;
//CountDownLatch
public class T9 {
public static void main(String[] args) throws Exception {
CountDownLatch countDownLatch = new CountDownLatch(5);
for (int i = 1; i < 6; i++) {
new Thread(new Runnable() {
@Override
public void run() {
countDownLatch.countDown();
System.out.println("" +Thread.currentThread().getName() + " 灭了");
}
},CountEnum.forEach_countEnum(i).name).start();
}
countDownLatch.await();
System.out.println("秦国统一天下");
}
}
public enum CountEnum {
ONE(1,"齐国"),
TWO(2,"楚国"),
THREE(3,"燕国"),
FOURE(4,"魏国"),
FIVE(5,"韩国"),
SIX(5,"赵国");
public int code;
public String name;
CountEnum(int code,String name){
this.code = code;
this.name = name;
}
CountEnum() {
}
public static CountEnum forEach_countEnum(int index){
CountEnum[] array = CountEnum.values();
for (CountEnum e: array) {
if (index == e.code){
return e;
}
}
return null;
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/05658977606614e6b2cb0217e4bfa91c.png)