CompletableFuture 和 CompletableFuture.allOf 多线程的使用
CompletableFuture<Map<String, String>> mapFuture1 = CompletableFuture.supplyAsync(() -> this.get1(projectCodeList));
CompletableFuture<Map<String, String>> mapFuture2 = CompletableFuture.supplyAsync(() -> this.get2(projectCodeList));
CompletableFuture<Map<String, String>> mapFuture3 = CompletableFuture.supplyAsync(() -> this.get3(projectCodeList));
CompletableFuture.allOf(mapFuture1, mapFuture2, mapFuture3);
Map<String, String> map1 = new HashMap<>();
Map<String, String> map2 = new HashMap<>();
Map<String, String> map3 = new HashMap<>();
try {
map1.putAll(mapFuture1.get());
map2.putAll(mapFuture2.get());
map3.putAll(mapFuture3.get());
} catch (Exception e) {
logger.error("错了");
e.printStackTrace();
}
标题:CompletableFuture 和 CompletableFuture.allOf 多线程的使用
作者:temp12138
地址:https://solo.mfyzl.icu/articles/2024/06/24/1719216517785.html
废话短说