码迷,mamicode.com
首页 > 其他好文 > 详细

枚举加countdownLatch的使用

时间:2019-10-13 18:30:26      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:demo   return   current   values   stack   down   exception   yar   one   

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;
    }
}

 

枚举加countdownLatch的使用

标签:demo   return   current   values   stack   down   exception   yar   one   

原文地址:https://www.cnblogs.com/xiufengchen/p/11667387.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!