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) {
           ......           
        }
    }
上一篇下一篇

猜你喜欢

热点阅读