CompletableFuture 进步接口性能
// 依据排口查问因子信息(异步)CompletableFuture<List<FactorInfo>> listCompletableFuture =
CompletableFuture.supplyAsync(() -> mapper.loadPortFactor(spec.getPort().getId()), EXECUTOR);
// 排口所配因子
List<FactorInfo> factorInfos = listCompletableFuture.join();
// 异步 所以用 ConcurrentHashMap
ConcurrentHashMap<String, List<Map>> testmap1 = new ConcurrentHashMap<>();
// 异步查问所有因子的数据
CompletableFuture[] completableFutures = factorInfos.stream().map(factor -> CompletableFuture.runAsync(() -> {DataReportSpec dataReportSpec = new DataReportSpec();
BeanUtils.copyProperties(spec, dataReportSpec);
dataReportSpec.setFactor(factor);
testmap1.put(factor.getCode(), mapper.loadGasBySpec(dataReportSpec));
}, EXECUTOR)).toArray(CompletableFuture[]::new);
// 期待所有执行结束
CompletableFuture.allOf(completableFutures).join();
本文由 mdnice 多平台公布