CompletableFuture下多线程子任务回滚

送你一朵小红花送你一朵小红花 · 2022-09-02 10:01
CompletableFuture<Integer> 1= CompletableFuture.supplyAsync( () -> 任务1); CompletableFuture<Integer> 2= CompletableFuture.supplyAsync( () -> 任务2); CompletableFuture<Integer> 3= CompletableFuture.supplyAsync(() -> 任务3); CompletableFuture<Integer> 4= CompletableFuture.supplyAsync(() -> 任务4); CompletableFuture<Integer> 5= CompletableFuture.supplyAsync(() -> 任务5); CompletableFuture<Integer> 6= CompletableFuture.supplyAsync(() ->任务6); //等待任务 CompletableFuture<Void> voidCompletableFuture = CompletableFuture.allOf(1, 2, 3, 4, 5,6); //异常 回滚所有子任务 //获取任务结果 voidCompletableFuture.get();
0 个回答
暂无回答