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

CountDownLanchDemo

时间:2018-06-03 17:30:08      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:exec   TE   inter   current   sig   for   div   create   结束   

package com.fh.interview;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author
 * @create 2018-06-03 下午3:35
 **/
public class CountDownLauchDemo {

    private static CountDownLatch startSign = new CountDownLatch(1);

    private static CountDownLatch endSign = new CountDownLatch(6);


    public static void main(String[] args) throws Exception {
        ExecutorService pool = Executors.newFixedThreadPool(6);
        for (int i=0;i<6;i++){
            pool.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        System.out.println(Thread.currentThread().getName()+"等待裁判吹哨");
                        startSign.await();
                        System.out.println(Thread.currentThread().getName()+"全力冲刺");
                        endSign.countDown();
                        System.out.println(Thread.currentThread().getName()+"到达终点");
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            });
        }

        System.out.println("吹啦");
        startSign.countDown();
        endSign.await();
        System.out.println("结束额");
        pool.shutdown();
    }
}

 

CountDownLanchDemo

标签:exec   TE   inter   current   sig   for   div   create   结束   

原文地址:https://www.cnblogs.com/nihaofenghao/p/9129510.html

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