线程同步-CountDownLatch
2017-02-13 21:03
211 查看
应用场景:
有一个任务想要往下执行,但必须要等到其他的任务执行完毕后才可以继续往下执行。
假如我们这个想要继续往下执行的任务调用一个CountDownLatch对象的await()方法,其他的任务执行完自己的任务后调用同一个CountDownLatch对象上的countDown()方法,这个调用await()方法的任务将一直阻塞等待,直到这个CountDownLatch对象的计数值减
到0为止。
主要方法:
public CountDownLatch(int count);
public void countDown();
public void await() throws InterruptedException
此方法休眠中断条件: CountDownLatch 内部计数器到达0或者特定的时间过去了。
有一个任务想要往下执行,但必须要等到其他的任务执行完毕后才可以继续往下执行。
假如我们这个想要继续往下执行的任务调用一个CountDownLatch对象的await()方法,其他的任务执行完自己的任务后调用同一个CountDownLatch对象上的countDown()方法,这个调用await()方法的任务将一直阻塞等待,直到这个CountDownLatch对象的计数值减
到0为止。
主要方法:
public CountDownLatch(int count);
public void countDown();
public void await() throws InterruptedException
此方法休眠中断条件: CountDownLatch 内部计数器到达0或者特定的时间过去了。
public void await(long timeout, TimeUnit unit) throws InterruptedException 此方法休眠中断条件: CountDownLatch 内部计数器到达0或者特定的时间过去了。
相关文章推荐
- CodeForces 451B. Sort the Array
- Oracle优化器的基础知识(二)
- MyBatis表级联立
- java输出99乘法表
- 关于CSS的几种居中
- linux环境下串口读取不了
- 2016福州大学软件工程实践调查问卷报告
- Android 7.1.1源码下载
- Window下JDK\Tomcat环境变量的配置
- Glide-占位图以及加载动画
- package.json中 npm依赖包版本前的符号的意义
- [Easy]Two Sum
- 关于jquery自定义事件
- automake - 使用 autotools 工具集
- 后缀表达式计算的代码实现
- CentOs Mysql主从复制与读写分离
- 斐波那契博弈
- hdoj1094
- 字符串匹配KMP算法中Next[]数组和Nextval[]数组求法
- c#基类继承