package com.hikvision.ostore.commons.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.*;
/**
* @ClassName AsyncThreadPoolConfiguration
* @Description 线程池配置
* @Date 2022/3/28 17:27
* @Version 1.0
*/
@Slf4j
@Configuration
public class AsyncThreadPoolConfiguration {
@Value("${threadPool.poolSize:16}")
private int poolSize;
@Value("${threadPool.maximumPoolSize:64}")
private int maximumPoolSize;
@Value("${threadPool.queueSize:300000}")
private int queueSize;
@Value("${threadPool.keepAliveTime:10}")
private long keepAliveTime;
@Value("${threadPool.orderPoolSize:1}")
private int orderPoolSize;
/**
* 订单的线程池
*
* @return
*/
@Bean(name = "orderTaskExecutor")
public ThreadPoolExecutor orderTaskExecutor() {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(orderPoolSize, maximumPoolSize,
keepAliveTime, TimeUnit.MINUTES,
new LinkedBlockingQueue<>(queueSize),
new ThreadPoolExecutor.CallerRunsPolicy());
log.info("order task thread pool : poolSize= [{}] , maximumPoolSize = [{}] , queueSize = [{}] , keepAliveTime = [{}]"
, poolSize, maximumPoolSize, queueSize, keepAliveTime);
return threadPoolExecutor;
}
/**
* 物料的线程池
*
* @return
*/
@Bean(name = "materialTaskExecutor")
public ThreadPoolExecutor materialTaskExecutor() {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(poolSize, maximumPoolSize,
keepAliveTime, TimeUnit.MINUTES,
new LinkedBlockingQueue<>(queueSize),
new ThreadPoolExecutor.CallerRunsPolicy());
log.info("material task thread pool : poolSize= [{}] , maximumPoolSize = [{}] , queueSize = [{}] , keepAliveTime = [{}]"
, poolSize, maximumPoolSize, queueSize, keepAliveTime);
return threadPoolExecutor;
}
}
线程池配置
最新推荐文章于 2023-07-24 17:48:11 发布