liian2019
2020-12-17 19:01:54 +08:00
public static void test() throws Exception{
Map<String,String> resultMap = new HashMap<>();
CompletableFuture.allOf(CompletableFuture.supplyAsync(() -> {
// 调用 A
String aResult = "Hello";
resultMap.put("A",aResult);
return aResult;
}, executor).thenAcceptAsync(aResult -> {
// 调用 B
String bResult = aResult + " World";
resultMap.put("B",bResult);
}), CompletableFuture.runAsync(() -> {
// 调用 C
String cResult = "CValue";
resultMap.put("C",cResult);
},executor), CompletableFuture.runAsync(() -> {
// 调用 D
String dResult = "DValue";
resultMap.put("D",dResult);
},executor),
CompletableFuture.runAsync(() -> {
// 调用 E
String eResult = "EValue";
resultMap.put("E",eResult);
},executor)).join();
System.out.println(JSON.toJSONString(resultMap));
}