zoukankan      html  css  js  c++  java
  • CountDownLatch

    import java.util.ArrayList;
    import java.util.List;
    import java.util.concurrent.CountDownLatch;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;

    public class TestCountDownLatch {

    public static void main(String[] args) throws InterruptedException {
    long start = System.currentTimeMillis();
    // 开始的倒数锁
    final CountDownLatch begin = new CountDownLatch(1);
    // 结束的倒数锁
    final CountDownLatch end = new CountDownLatch(10000);
    List<String> list=new ArrayList<String>();
    // 十名选手
    final ExecutorService exec = Executors.newFixedThreadPool(10);
    for (int index = 0; index < 10000; index++) {
    final int NO = index;
    Runnable run = new Runnable() {
    public void run() {
    try {
    begin.await();
    System.out.println(NO);
    String temp="AA"+NO;
    list.add(temp);
    Thread.sleep((long) (Math.random() * 10));
    } catch (InterruptedException e) {
    } finally {
    end.countDown();
    }
    }
    };
    System.out.println(run);
    exec.submit(run);
    }
    System.out.println("Game Start");
    begin.countDown();
    end.await();
    System.out.println("Game Over");
    exec.shutdown();
    System.out.println("num:"+list.size());
    // for(String s:list){
    // System.out.println("数据打印:"+s);
    // }
    System.out.print("共计用时 ");
    System.out.println(System.currentTimeMillis() - start);
    }
    }

  • 相关阅读:
    Aapache Tomcat AJP 文件包含漏洞(CVE-2020-1938)
    Tomcat 任意文件上传漏洞(CVE-2017-12615)
    Apache Shiro 1.2.4反序列化漏洞(CVE-2016-4437)
    Redis 4.x/5.x 未授权访问漏洞
    mysql 5.7关于group by显示多列的一个潜坑
    Python
    购物车作业
    Lesson2
    a good website to test OTP
    利用fidder发送request
  • 原文地址:https://www.cnblogs.com/justuntil/p/9636087.html
Copyright © 2011-2022 走看看