枚举加countdownLatch的使用
Posted xiufengchen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了枚举加countdownLatch的使用相关的知识,希望对你有一定的参考价值。
package com.cxy.juc; import java.util.concurrent.CountDownLatch; public class CountDownlatchDemo { public static void main(String[] args) { CountDownLatch countDownLatch =new CountDownLatch(6); for (int i = 1; i <=6 ; i++) { new Thread(()->{ System.out.println("1"+" "+Thread.currentThread().getName()); countDownLatch.countDown(); },Count.fore(i).getMsg()).start(); } try { countDownLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("2"); } }
package com.cxy.juc; import com.sun.javafx.scene.control.behavior.TwoLevelFocusBehavior; public enum Count { ONE (1,"A"),TWO(2,"B"),THREE(3,"C"),FOUR(4,"D"),FIVE(5,"E"),SIX(6,"F"); private Integer num; private String msg; Count(Integer num, String msg) { this.num = num; this.msg = msg; } public Integer getNum() { return num; } public void setNum(Integer num) { this.num = num; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public static Count fore(int num){ Count[] myArray =Count.values(); for (Count count:myArray){ if (num ==count.getNum()){ return count; } } return null; } }
以上是关于枚举加countdownLatch的使用的主要内容,如果未能解决你的问题,请参考以下文章