CompletableFuture.allOf 可变参数传参
2021-04-13 本文已影响0人
毛嘟嘟
public void execute() {
try {
CompletableFuture<?>[] futures =
Arrays.stream(CardJobEnum.values())
.map(e -> CompletableFuture.runAsync(() -> handle(e)))
.collect(Collectors.toSet()).toArray(CompletableFuture[]::new);
CompletableFuture.allOf(futures).get();
} catch (Exception e) {
......
}
}