zoukankan      html  css  js  c++  java
  • 实现多线程同步 CountDownLatch

    原文链接:https://blog.csdn.net/QQxiaoqiang1573/article/details/83008332

    方法很少:

    1、public CountDownLatch(int count)
         构造函数,需传入计数的总数。

    2、public void await() 
         阻塞线程,直到总计数值为0

    3、public void countDown()
         当前总计数减一

    4、public long getCount()
         当前总计数

    下面是一个例子,可以使十个线程同时进行操作

    final CountDownLatch latch = new CountDownLatch(1);
    int threadCount = 10;
    for (int i = 0; i < threadCount; i++) {
        final int finalI = i;
        new Thread() {
            @Override
            public void run() {
                try {
                    latch.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                Log.d(TAG, "run: "+ finalI);
            }
        }.start();
    }
    latch.countDown();
  • 相关阅读:
    比SRCNN效果好的传统超分辨率算法汇总
    CSS3 2D转换
    CSS3 文本效果
    CSS3 Gradients(渐变)
    CSS3 背景
    CSS3 圆角
    CSS3 边框
    CSS3 简介
    CSS 属性选择器
    CSS 媒体类型
  • 原文地址:https://www.cnblogs.com/zhaozilongcjiajia/p/11752040.html
Copyright © 2011-2022 走看看