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. 10
      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.context.ApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Service
public class OrderServiceImpl implements OrderService, ITxTransaction {
@ -80,9 +77,10 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
private RedisTemplate redisTemplate;
@Autowired
private ApplicationContext applicationContext;
@Autowired
private ThreadPoolTaskExecutor executor;
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
public List<Order> selectByAdIdAndStatus(String adId, String... status) {
@ -320,7 +318,7 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
}
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"));
}
}

Loading…
Cancel
Save