使用自定义线程池

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

@@ -35,6 +35,7 @@ import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.SecurityUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.bean.BeanUtils;
import com.jsowell.common.util.spring.SpringUtils;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.service.*;
@@ -54,6 +55,7 @@ import org.apache.commons.collections4.CollectionUtils;
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 org.springframework.transaction.annotation.Transactional;
@@ -146,6 +148,9 @@ public class OrderService {
@Resource
private RedisCache redisCache;
// 引入线程池
private ThreadPoolTaskExecutor executor = SpringUtils.getBean("threadPoolTaskExecutor");
/**
* 生成订单
*
@@ -575,7 +580,7 @@ public class OrderService {
} catch (Exception e) {
log.error("异步发送获取实时数据指令error", e);
}
});
}, executor);
}
vo.setOrderCode(orderBasicInfo.getOrderCode());
@@ -680,7 +685,7 @@ public class OrderService {
} catch (Exception e) {
log.error("后管查询订单详情时把redis中的实时数据存到表发生异常", e);
}
});
}, executor);
return vo;
}
@@ -805,7 +810,7 @@ public class OrderService {
} catch (Exception e) {
log.error("人工结算订单 推送第三方平台订单信息error, orderCode:{}", orderBasicInfo.getOrderCode(), e);
}
});
}, executor);
return true;
}
@@ -1190,7 +1195,7 @@ public class OrderService {
} catch (Exception e) {
log.error("更新冻结金额 支付成功后全部冻结error", e);
}
});
}, executor);
// 支付订单成功
PayOrderSuccessCallbackDTO callbackDTO = PayOrderSuccessCallbackDTO.builder()
@@ -1209,7 +1214,7 @@ public class OrderService {
} catch (Exception e) {
log.error("异步推送第三方平台启动充电逻辑 error", e);
}
});
}, executor);
} else if (StringUtils.equals(scenarioType, ScenarioEnum.BALANCE.getValue())) { // 2-充值余额
// 充值余额成功
UpdateMemberBalanceDTO dto = new UpdateMemberBalanceDTO();

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()都会阻塞并获取线程的执行情况