线程同步-CountDownLatch
2017-02-12 17:03
197 查看
应用场景:
有一个任务想要往下执行,但必须要等到其他的任务执行完毕后才可以继续往下执行。
假如我们这个想要继续往下执行的任务调用一个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或者特定的时间过去了。
相关文章推荐
- 线程同步工具之CountDownLatch
- 线程同步-CountDownLatch
- 线程同步辅助类—CountDownLatch
- java多线程(13)--线程同步工具之CountDownLatch
- 线程同步辅助类——CountDownLatch
- 线程同步工具——CountDownLatch
- 线程同步工具之CountDownLatch
- 线程同步工具类——CountDownLatch
- 线程同步-CountDownLatch
- 线程同步工具-CountDownLatch
- java多线程中线程同步工具-CountDownLatch
- 线程同步-CountDownLatch
- Java并发学习之十七——线程同步工具之CountDownLatch
- 线程同步工具之CountDownLatch
- java的线程同步
- JAVA concurrent包学习--CountDownLatch
- 利用事件对象实现线程同步
- [ 高并发]Java高并发编程系列第二篇--线程同步
- 线程同步之临界区
- Java SE学习笔记:创建(Thread/Runable),线程安全,线程同步,同步锁机制