3.1.5 倒计时器:CountDownLatch

Posted anxbb

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了3.1.5 倒计时器:CountDownLatch相关的知识,希望对你有一定的参考价值。

package 第三章.倒计时器CountDownLatch;

import java.util.concurrent.CountDownLatch;

/**
* Created by zzq on 2018/1/24.
*/
public class CountDoenLatchTest implements Runnable{
static CountDownLatch countDownLatch=new CountDownLatch(3);
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
countDownLatch.countDown();
}

public static void main(String[] args) throws InterruptedException {
CountDoenLatchTest countDoenLatchTest=new CountDoenLatchTest();
Thread thread=new Thread(countDoenLatchTest);
Thread thread2=new Thread(countDoenLatchTest);
Thread thread3=new Thread(countDoenLatchTest);
thread.start();
// thread2.start();
// thread3.start();
countDownLatch.await();
System.out.println("主线程执行----------");
}
}

以上是关于3.1.5 倒计时器:CountDownLatch的主要内容,如果未能解决你的问题,请参考以下文章

并发工具类:倒计时器-CountDownLatch

多线程控制工具类--倒计时器CountDownLatch的使用(模仿火箭发射)

java并发学习03---CountDownLatch 和 CyclicBarrier

线程工具类 - CountDownLatch

多线程之倒计时器CountDownLatch和循环栅栏CyclicBarrier

JUC并发编程 共享模式之工具 JUC CountdownLatch(倒计时锁) -- CountdownLatch(使用CountdownLatch原理改进: 配合线程池使用)