thread pool update

master
fengyu.wang 4 years ago
parent 26f71afade
commit 96691ea013
  1. 21
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/common/config/ApplicationConfig.java
  2. 40
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/service/impl/OrderServiceImpl.java

@ -0,0 +1,21 @@
package com.blockchain.server.otc.common.config;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.util.concurrent.ThreadPoolExecutor;
@Component
public class ApplicationConfig {
@Bean
public ThreadPoolTaskExecutor executor() {
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setCorePoolSize(5);
threadPoolTaskExecutor.setMaxPoolSize(10);
threadPoolTaskExecutor.setQueueCapacity(50);
threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
threadPoolTaskExecutor.setThreadNamePrefix("executor-");
return threadPoolTaskExecutor;
}
}

@ -31,15 +31,12 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Service @Service
public class OrderServiceImpl implements OrderService, ITxTransaction { public class OrderServiceImpl implements OrderService, ITxTransaction {
@ -80,9 +77,10 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
@Autowired @Autowired
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@Autowired
private ThreadPoolTaskExecutor executor;
private static final BigDecimal DECIMAL_DISH = new BigDecimal("0.1"); //下单金额计算的偏差值 private static final BigDecimal DECIMAL_DISH = new BigDecimal("0.1"); //下单金额计算的偏差值
private static final ExecutorService EXECUTOR_SERVICE = new ThreadPoolExecutor(5, 10, 0, TimeUnit.MINUTES, new PriorityBlockingQueue<>());
@Override @Override
public List<Order> selectByAdIdAndStatus(String adId, String... status) { public List<Order> selectByAdIdAndStatus(String adId, String... status) {
@ -302,25 +300,25 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDtoByUserId(userId, redisTemplate); YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDtoByUserId(userId, redisTemplate);
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(), payType,BigDecimal.ZERO.subtract(order.getTurnover())); ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(), payType, BigDecimal.ZERO.subtract(order.getTurnover()));
if(resultDTO.getCode()==200 && resultDTO.getData()) { if (resultDTO.getCode() == 200 && resultDTO.getData()) {
//更新订单状态 //更新订单状态
receiptOrPayUpdateOrder(order, UserHandleConstants.PAY); receiptOrPayUpdateOrder(order, UserHandleConstants.PAY);
//记录用户操作 //记录用户操作
insertUserHandleLog(userId, order.getOrderNumber(), UserHandleConstants.PAY); insertUserHandleLog(userId, order.getOrderNumber(), UserHandleConstants.PAY);
//确认付款发送提示消息 //确认付款发送提示消息
sendNewOrderMsg(JgMsgEnums.CONFIRM_BUYER_SELL.getName(), JgMsgEnums.CONFIRM_BUYER_BUY.getName(), sendNewOrderMsg(JgMsgEnums.CONFIRM_BUYER_SELL.getName(), JgMsgEnums.CONFIRM_BUYER_BUY.getName(),
order.getSellUserId(), order.getBuyUserId(), order.getId()); order.getSellUserId(), order.getBuyUserId(), order.getId());
//发送手机消息通知 //发送手机消息通知
pushToSingle(order.getSellUserId(), order.getId(), PushEnums.OTC_ORDER_PAY.getPushType()); pushToSingle(order.getSellUserId(), order.getId(), PushEnums.OTC_ORDER_PAY.getPushType());
}else{ } else {
throw new OtcException(OtcEnums.FREEBALANCE_NOT_ENOUGH); throw new OtcException(OtcEnums.FREEBALANCE_NOT_ENOUGH);
} }
if (BooleanUtils.isTrue(ad.getBuiltIn())) { if (BooleanUtils.isTrue(ad.getBuiltIn())) {
EXECUTOR_SERVICE.execute(() -> applicationContext.getBean(OrderService.class).receipt(order.getSellUserId(), orderId, "123456")); executor.execute(() -> applicationContext.getBean(OrderService.class).receipt(order.getSellUserId(), orderId, "123456"));
} }
} }
@ -343,8 +341,8 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
checkOrderCanHandle(order, userId, UserHandleConstants.RECEIPT); checkOrderCanHandle(order, userId, UserHandleConstants.RECEIPT);
YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDtoByUserId(userId, redisTemplate); YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDtoByUserId(userId, redisTemplate);
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(),order.getOrderPayType(),order.getTurnover()); ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(), order.getOrderPayType(), order.getTurnover());
if(resultDTO.getCode()==200 && resultDTO.getData()) { if (resultDTO.getCode() == 200 && resultDTO.getData()) {
//更新订单状态 //更新订单状态
@ -362,7 +360,7 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
order.getSellUserId(), order.getBuyUserId(), order.getId()); order.getSellUserId(), order.getBuyUserId(), order.getId());
//发送手机消息通知 //发送手机消息通知
pushToSingle(order.getBuyUserId(), order.getId(), PushEnums.OTC_ORDER_RECEIPT.getPushType()); pushToSingle(order.getBuyUserId(), order.getId(), PushEnums.OTC_ORDER_RECEIPT.getPushType());
}else{ } else {
throw new OtcException(OtcEnums.ERROR_IN_WALLET_CALL); throw new OtcException(OtcEnums.ERROR_IN_WALLET_CALL);
} }
} }

Loading…
Cancel
Save