线程池配置
@Configuration
public class TaskConfig {
@Bean("taskModuleExecutor")
public ThreadPoolTaskExecutor taskExecutor() {
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setCorePoolSize(64);// 核心线程数
threadPoolTaskExecutor.setMaxPoolSize(200);// 最大线程数
threadPoolTaskExecutor.setQueueCapacity(1000);// 队列最大长度
threadPoolTaskExecutor.setKeepAliveSeconds(60);// 线程池维护线程所允许的空闲时间,默认为60s
threadPoolTaskExecutor.setThreadNamePrefix("task-concurrent-work");
threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
threadPoolTaskExecutor.initialize();
return threadPoolTaskExecutor;
}
}
Reject策略