CountDownLatch CompletableFuture
时间: 2023-10-13 07:03:47 浏览: 214
CountDownLatch和CompletableFuture是Java中的两个多线程编程工具。CountDownLatch是一个计数器,它允许一个或多个线程等待其他线程执行完毕后再继续执行。CountDownLatch的主要方法有:await()、await(long timeout, TimeUnit unit)和countDown()。调用await()方法的线程会被挂起,直到计数值为0才会继续执行。await(long timeout, TimeUnit unit)方法允许等待一定的时间后继续执行,适用于允许丢失部分数据的场景。countDown()方法将计数值减1。CountDownLatch通常用于主线程等待其他子线程任务都执行完毕后再执行,例如在多模块数据加速加载、治理大批量数据下游接口超时等场景中使用。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [搬砖日记-CountDownLatch和CompletableFuture的使用](https://blog.csdn.net/weixin_40990818/article/details/123453351)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文