zoukankan      html  css  js  c++  java
  • CountDownLanchDemo

    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();
        }
    }
  • 相关阅读:
    10月9日学习日志
    10月2日学习日志
    11月3日学习日志
    10月5日学习日志
    10月6日学习日志
    10月7日学习日志
    11月4日学习日志
    AccessDatabaseEngine.exe 32位64安装失败问题
    国产各安卓系统接收消息在杀进程后
    SAP容差组
  • 原文地址:https://www.cnblogs.com/nihaofenghao/p/9129510.html
Copyright © 2011-2022 走看看