如果我使用get(),则需要CompletableFuture.allOf

时间:2019-06-24 21:17:49

标签: java-8 java.util.concurrent completable-future

我的控制器正在根据某些条件进行异步呼叫获取国家/地区列表。

CompletableFuture<List<Country>> countriesByLanguageFuture = countryClient.getCountriesByLanguage("fr");
CompletableFuture<List<Country>> countriesByRegionFuture = countryClient.getCountriesByRegion("europe");

现在我需要获取以下国家/地区列表。

List<country> ctryList1= countriesByLanguageFuture.get();
List<country> ctryList2= countriesByRegionFuture.get();

现在我的问题是因为get()被阻止了,我真的必须做下面的事情来等待所有过程完成。

CompletableFuture.allOf(countriesByLanguageFuture, countriesByRegionFuture);

我想我在某个地方迷路了。

0 个答案:

没有答案