【发布时间】:2020-03-24 05:23:42
【问题描述】:
我有一个场景,我应该在一个方法中同时调用 4 个不同的外部服务,如果线程中的任何一个将首先获取数据,那么我需要取消线程的其余部分并返回响应。
class ProductService{
public List<Product> getProducts(){
// logic to call multiple services concurrently
// if any of the thread get the data then cancel the rest concurrent call gracefully
// return the response
}
}
谁能帮我实现这个逻辑。
【问题讨论】:
-
您想无限期地阻止,直到收到第一个响应,对吧?
标签: java multithreading spring-boot concurrency parallel-processing