删除无用线程池配置,修改使用线程池核心数量

This commit is contained in:
walker-sheng 2020-11-26 13:35:24 +08:00
parent 6292dee955
commit a6e8c3cc49

View File

@ -13,21 +13,6 @@ import java.util.concurrent.ThreadPoolExecutor;
@Configuration
@EnableAsync
public class TaskExecutorConfiguration {
/***
* 创建仿真异步逻辑执行线程池
* @return
*/
@Bean("simulationExecutor")
public TaskExecutor simulationExecutor(Environment env) {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setThreadNamePrefix("simulation-executor-");
taskExecutor.setCorePoolSize(1);
taskExecutor.setMaxPoolSize(1);
taskExecutor.setQueueCapacity(10);
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
taskExecutor.initialize();
return taskExecutor;
}
/***
* 创建新仿真异步逻辑执行线程池
@ -37,8 +22,8 @@ public class TaskExecutorConfiguration {
public TaskExecutor nsExecutor(Environment env) {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setThreadNamePrefix("ns-executor-");
taskExecutor.setCorePoolSize(2);
taskExecutor.setMaxPoolSize(2);
taskExecutor.setCorePoolSize(4);
taskExecutor.setMaxPoolSize(4);
taskExecutor.setQueueCapacity(100);
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
taskExecutor.initialize();
@ -53,51 +38,12 @@ public class TaskExecutorConfiguration {
public TaskExecutor realDeviceExecutor(Environment env) {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setThreadNamePrefix("real-device-executor-");
taskExecutor.setCorePoolSize(1);
taskExecutor.setMaxPoolSize(1);
taskExecutor.setCorePoolSize(4);
taskExecutor.setMaxPoolSize(4);
taskExecutor.setQueueCapacity(100);
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
taskExecutor.initialize();
return taskExecutor;
}
/***
* 异步逻辑执行线程池
* @return
*/
@Bean("commonExecutor")
public TaskExecutor commonExecutor(Environment env) {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setThreadNamePrefix("common-executor-");
taskExecutor.setMaxPoolSize(20);
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
taskExecutor.initialize();
return taskExecutor;
}
/**定时任务调度器*/
@Bean("scheduler")
public ThreadPoolTaskScheduler threadPoolTaskScheduler(){
return new ThreadPoolTaskScheduler();
}
/***
* 创建仿真UDP数据处理执行线程池
* @return
*/
@Bean("socketExecutor")
public TaskExecutor socketExecutor(Environment env) {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setThreadNamePrefix("socket-executor-");
taskExecutor.setCorePoolSize(1);
taskExecutor.setMaxPoolSize(1);
taskExecutor.setQueueCapacity(10);
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
taskExecutor.initialize();
return taskExecutor;
}
}