CompletableFuture<Integer> task1 = CompletableFuture.supplyAsync(() -> 100);
CompletableFuture<Integer> task2 = CompletableFuture.supplyAsync(() -> 100);
Integer sum1 = task1.join() + task2.join();
Integer sum2 = task1.thenCombine(task2, (resp1, resp2) -> {
return resp1 + resp2;
}).join();
請(qǐng)問sum1和sum2的兩種寫法,有什么不同呢,各有什么好處?
CompletableFuture 使用詳解1、 runAsync 和 supplyAsync方法 CompletableFuture 提供了四個(gè)靜態(tài)方法來創(chuàng)建一個(gè)異步操作欢搜。 沒有指定Executor的方法會(huì)使用For...