使用自定义线程池

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

@@ -11,6 +11,7 @@ import com.jsowell.common.enums.DelFlagEnum;
import com.jsowell.common.enums.ykc.*;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.*;
import com.jsowell.common.util.spring.SpringUtils;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.service.*;
@@ -27,6 +28,7 @@ import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -41,6 +43,9 @@ import java.util.stream.Collectors;
public class PileService {
private final Logger log = LoggerFactory.getLogger(PileService.class);
// 引入线程池
private ThreadPoolTaskExecutor executor = SpringUtils.getBean("threadPoolTaskExecutor");
@Autowired
private TransactionService pileTransactionService;
@@ -156,7 +161,7 @@ public class PileService {
/**
* 前端扫码跳转接口
*/
public AppletPileDetailVO getPileDetailByPileSn(String param) throws Exception {
public AppletPileDetailVO getPileDetailByPileSnV2(String param) throws Exception {
AppletPileDetailVO vo = null;
log.info("查询充电枪口详情-getPileDetailByPileSn, param:{}", param);
if (StringUtils.isBlank(param)) {
@@ -200,7 +205,7 @@ public class PileService {
return vo;
}
public AppletPileDetailVO getPileDetailByPileSnOld(String param) throws Exception {
public AppletPileDetailVO getPileDetailByPileSn(String param) throws Exception {
AppletPileDetailVO vo = null;
log.info("查询充电枪口详情-getPileDetailByPileSn, param:{}", param);
if (StringUtils.isBlank(param)) {
@@ -231,16 +236,16 @@ public class PileService {
}
// 查询充电桩下枪口信息
CompletableFuture<List<ConnectorInfoVO>> connectorInfoListFuture = FutureUtil.supplyAsync(() -> pileConnectorInfoService.selectConnectorInfoList(pileSn));
log.info("查询充电枪口详情-supplyAsync-selectConnectorInfoList:{}", connectorInfoListFuture);
CompletableFuture<List<ConnectorInfoVO>> connectorInfoListFuture = CompletableFuture.supplyAsync(() -> pileConnectorInfoService.selectConnectorInfoList(pileSn), executor);
// log.info("查询充电枪口详情-supplyAsync-selectConnectorInfoList:{}", connectorInfoListFuture);
// 查计费模板信息
CompletableFuture<List<BillingPriceVO>> billingPriceFuture = FutureUtil.supplyAsync(() -> pileBillingTemplateService.queryBillingPrice(pileInfoVO.getStationId()));
log.info("查询充电枪口详情-supplyAsync-queryBillingPrice:{}", billingPriceFuture);
CompletableFuture<List<BillingPriceVO>> billingPriceFuture = CompletableFuture.supplyAsync(() -> pileBillingTemplateService.queryBillingPrice(pileInfoVO.getStationId()), executor);
// log.info("查询充电枪口详情-supplyAsync-queryBillingPrice:{}", billingPriceFuture);
// 查询运营商信息
CompletableFuture<MerchantInfoVO> merchantInfoVOFuture = FutureUtil.supplyAsync(() -> pileMerchantInfoService.getMerchantInfoVO(pileInfoVO.getMerchantId()));
log.info("查询充电枪口详情-supplyAsync-getMerchantInfoVO:{}", merchantInfoVOFuture);
CompletableFuture<MerchantInfoVO> merchantInfoVOFuture = CompletableFuture.supplyAsync(() -> pileMerchantInfoService.getMerchantInfoVO(pileInfoVO.getMerchantId()), executor);
// log.info("查询充电枪口详情-supplyAsync-getMerchantInfoVO:{}", merchantInfoVOFuture);
CompletableFuture all = FutureUtil.allOf(connectorInfoListFuture, merchantInfoVOFuture, billingPriceFuture);
// .join()和.get()都会阻塞并获取线程的执行情况