Map<String, Map<String, Object>> leakLine76Map = caijiStatistics(CaijiProductEnums.LEAKTEST76.getProductName(), CaijiProductEnums.LEAKTEST76.getDataSource(),caijiStatisticDTO); // 试漏线82数据统计 Map<String, Map<String, Object>> leakLine82Map = caijiStatistics(CaijiProductEnums.LEAKTEST82.getProductName(),CaijiProductEnums.LEAKTEST82.getDataSource(),caijiStatisticDTO); // 试漏线110数据统计 Map<String, Map<String, Object>> leakLine110Map = caijiStatistics(CaijiProductEnums.LEAKTEST110.getProductName(), CaijiProductEnums.LEAKTEST110.getDataSource(),caijiStatisticDTO); // 试漏线111数据统计 Map<String, Map<String, Object>> leakLine111Map = caijiStatistics(CaijiProductEnums.LEAKTEST111.getProductName(),CaijiProductEnums.LEAKTEST111.getDataSource(),caijiStatisticDTO); // 试漏线112数据统计 Map<String, Map<String, Object>> leakLine112Map = caijiStatistics(CaijiProductEnums.LEAKTEST112.getProductName(),CaijiProductEnums.LEAKTEST112.getDataSource(),caijiStatisticDTO); // 试漏线118数据统计 Map<String, Map<String, Object>> leakLine118Map = caijiStatistics(CaijiProductEnums.LEAKTEST118.getProductName(), CaijiProductEnums.LEAKTEST118.getDataSource(),caijiStatisticDTO);改为异步执行
时间: 2024-01-29 21:04:26 浏览: 70
VC使用CRT调试功能检测内存泄露
可以将这些代码块封装成一个异步方法,使用CompletableFuture来实现异步执行,示例代码如下:
```
CompletableFuture<Map<String, Map<String, Object>>> leakLine76Future =
CompletableFuture.supplyAsync(() ->
caijiStatistics(CaijiProductEnums.LEAKTEST76.getProductName(),
CaijiProductEnums.LEAKTEST76.getDataSource(),
caijiStatisticDTO));
CompletableFuture<Map<String, Map<String, Object>>> leakLine82Future =
CompletableFuture.supplyAsync(() ->
caijiStatistics(CaijiProductEnums.LEAKTEST82.getProductName(),
CaijiProductEnums.LEAKTEST82.getDataSource(),
caijiStatisticDTO));
CompletableFuture<Map<String, Map<String, Object>>> leakLine110Future =
CompletableFuture.supplyAsync(() ->
caijiStatistics(CaijiProductEnums.LEAKTEST110.getProductName(),
CaijiProductEnums.LEAKTEST110.getDataSource(),
caijiStatisticDTO));
CompletableFuture<Map<String, Map<String, Object>>> leakLine111Future =
CompletableFuture.supplyAsync(() ->
caijiStatistics(CaijiProductEnums.LEAKTEST111.getProductName(),
CaijiProductEnums.LEAKTEST111.getDataSource(),
caijiStatisticDTO));
CompletableFuture<Map<String, Map<String, Object>>> leakLine112Future =
CompletableFuture.supplyAsync(() ->
caijiStatistics(CaijiProductEnums.LEAKTEST112.getProductName(),
CaijiProductEnums.LEAKTEST112.getDataSource(),
caijiStatisticDTO));
CompletableFuture<Map<String, Map<String, Object>>> leakLine118Future =
CompletableFuture.supplyAsync(() ->
caijiStatistics(CaijiProductEnums.LEAKTEST118.getProductName(),
CaijiProductEnums.LEAKTEST118.getDataSource(),
caijiStatisticDTO));
// 组合所有异步任务
CompletableFuture<Void> allFutures = CompletableFuture.allOf(leakLine76Future, leakLine82Future,
leakLine110Future, leakLine111Future,
leakLine112Future, leakLine118Future);
// 等待所有异步任务执行完成
allFutures.join();
// 获取异步任务的结果
Map<String, Map<String, Object>> leakLine76Map = leakLine76Future.join();
Map<String, Map<String, Object>> leakLine82Map = leakLine82Future.join();
Map<String, Map<String, Object>> leakLine110Map = leakLine110Future.join();
Map<String, Map<String, Object>> leakLine111Map = leakLine111Future.join();
Map<String, Map<String, Object>> leakLine112Map = leakLine112Future.join();
Map<String, Map<String, Object>> leakLine118Map = leakLine118Future.join();
```
这样可以大大提高代码的执行效率。注意,由于使用了异步执行,因此获取异步任务的结果需要使用join()方法来等待任务执行完成。
阅读全文