【发布时间】:2019-04-04 11:58:22
【问题描述】:
我在 foreach 循环中定义了 completableFuture.supplyAsync(),所以每个条目(每个异步任务)添加一个列表,我需要从 completableFuture.supplyAsync() 获取最终列表(在所有异步任务添加列表之后)。如何实现这个?
代码sn-p:
unporcessedList.forEach(entry -> {
CompletableFuture<List<ChangeLog>> cf =
CompletableFuture.supplyAsync((Supplier<List<ChangeLog>>) () -> {
mongoDBHelper.processInMongo(entry, getObject(entry, map),entryList);
return entryList;
}, executor);
});
【问题讨论】:
标签: java concurrency java-8 completable-future