应用场景:

有一个任务想要往下执行,但必须要等到其他的任务执行完毕后才可以继续往下执行。

假如我们这个想要继续往下执行的任务调用一个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或者特定的时间过去了。

相关文章:

  • 2021-06-09
  • 2021-08-12
  • 2021-10-24
  • 2023-01-27
  • 2021-10-29
  • 2021-12-30
  • 2021-06-12
  • 2021-11-07
猜你喜欢
  • 2021-10-20
  • 2021-06-12
  • 2021-06-24
  • 2022-12-23
  • 2021-11-05
  • 2021-11-05
  • 2021-08-20
相关资源
相似解决方案