futures.forEach(CompletableFuture :: join)并行运行所有任务?

问题描述 投票:0回答:1

我有多个可完成的期货创建为:

CompletableFuture<Void> future1 = CompletableFuture.runAsync(() -> xxx);
CompletableFuture<Void> future2 = CompletableFuture.runAsync(() -> xxx);
List<CompletableFuture<Void>> futures = Lists.newArrayList(future1, future2);

当我在下面跑步时,这两个将来的任务会同时运行吗?一个将来抛出的异常会阻止另一个吗?

futures.forEach(CompletableFuture::join);
java multithreading completable-future
1个回答
0
投票

通过调用CompletableFuture.runAsync(...),任务将提交到CompletableFuture.runAsync(...)。该池由JVM管理。

© www.soinside.com 2019 - 2024. All rights reserved.