package com.demo.juc;
import java.util.concurrent.CountDownLatch;
import com.demo.enumTest.TestEnum;
public class TestCountDownLatch {
public static void main(String[] args) {
final CountDownLatch latch = new CountDownLatch(6);
for(int i=1;i<=6;i++){
final int index = i;
new Thread(()->{
System.out.println(Thread.currentThread().getName()+"国于公元"+TestEnum.get(index).getYear()+"年被灭。");
latch.countDown();
}, TestEnum.get(index).getName()).start();
}
//六国灭了之后,秦国才能一统天下
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.err.println("最终秦国一统天下");
}
}
最后修改:2019-06-23 10:47:16
© 著作权归作者所有
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付
