springboot 线程池

@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;
}


}
posted @ 2021-08-03 14:55  monkey66  阅读(106)  评论(0编辑  收藏  举报