枚举加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"+"\t"+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;
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值