@Configuration
public class MyThreadPoolTaskExecutor {
@Bean("bdpThreadPoolTaskExecutor")
public ThreadPoolTaskExecutor taskExecutor() {
ThreadPoolTaskExecutor poolExecutor = new ThreadPoolTaskExecutor();
// 核心线程数
poolExecutor.setCorePoolSize(3);
// 最大线程数
poolExecutor.setMaxPoolSize(9);
// 队列大小
poolExecutor.setQueueCapacity(30);
// 线程最大空闲时间
poolExecutor.setKeepAliveSeconds(2);
// 拒绝策略
poolExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
// 线程名称前缀
poolExecutor.setThreadNamePrefix("my-pool-");
poolExecutor.setWaitForTasksToCompleteOnShutdown(true);
poolExecutor.setAwaitTerminationSeconds(60);
poolExecutor.initialize();
return poolExecutor;
}
}