并行任务方法
thenCombine & thenCombineAsync
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
System.out.println("执行异步任务1");
return "执行异步任务1";
}).thenCombine(CompletableFuture.supplyAsync(() -> {
System.out.println("执行异步任务2");
return "执行异步任务2";
}), (result1, result2) -> {
System.out.println("执行异步任务1和异步任务2完成后的回调");
return result1 + result2;
});CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
System.out.println("执行异步任务1");
return "执行异步任务1";
}).thenCombineAsync(CompletableFuture.supplyAsync(() -> {
System.out.println("执行异步任务2");
return "执行异步任务2";
}), (result1, result2) -> {
System.out.println("执行异步任务1和异步任务2完成后的回调");
return result1 + result2;
});thenAcceptBoth & thenAcceptBothAsync
runAfterBoth和runAfterBothAsync
applyToEither和applyToEitherAsync
runAfterEither和runAfterEitherAsync
acceptEither和acceptEitherAsync
allOf
anyOf
最后更新于