使用自定义线程池

This commit is contained in:
Guoqs
2024-09-10 12:03:53 +08:00
parent 409307db85
commit 5e9beaf83a
13 changed files with 97 additions and 45 deletions

View File

@@ -8,6 +8,7 @@ import com.google.common.collect.Maps;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.util.PageUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.spring.SpringUtils;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.PileBasicInfo;
import com.jsowell.pile.domain.PileStationInfo;
@@ -24,6 +25,7 @@ import com.jsowell.thirdparty.amap.service.AMapService;
import com.jsowell.thirdparty.amap.util.AMapUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StopWatch;
@@ -49,6 +51,9 @@ import java.util.stream.Collectors;
@Service
public class AMapServiceImpl implements AMapService {
// 引入线程池
private ThreadPoolTaskExecutor executor = SpringUtils.getBean("threadPoolTaskExecutor");
@Autowired
private PileStationInfoService pileStationInfoService;
@@ -309,13 +314,13 @@ public class AMapServiceImpl implements AMapService {
stopWatch.start("拼装高德需要的格式数据-查询数据");
// 根据站点id查询计费模板
CompletableFuture<List<AMapPriceChargingInfo>> future1 = CompletableFuture.supplyAsync(() -> getPriceInfoByStationId(String.valueOf(stationInfoId)));
CompletableFuture<List<AMapPriceChargingInfo>> future1 = CompletableFuture.supplyAsync(() -> getPriceInfoByStationId(String.valueOf(stationInfoId)), executor);
// 根据站点id查询快、慢充设备数量
CompletableFuture<Map<String, Integer>> future2 = CompletableFuture.supplyAsync(() -> pileConnectorInfoService.getPileTypeNum(stationInfoId));
CompletableFuture<Map<String, Integer>> future2 = CompletableFuture.supplyAsync(() -> pileConnectorInfoService.getPileTypeNum(stationInfoId), executor);
// 根据站点查询站点下所有桩
CompletableFuture<List<AMapEquipmentInfo>> future3 = CompletableFuture.supplyAsync(() -> getPileListByStationId(String.valueOf(stationInfoId)));
CompletableFuture<List<AMapEquipmentInfo>> future3 = CompletableFuture.supplyAsync(() -> getPileListByStationId(String.valueOf(stationInfoId)), executor);
CompletableFuture<Void> all = CompletableFuture.allOf(future1, future2, future3);
// .join()和.get()都会阻塞并获取线程的执行情况