@Configuration标签:销毁,springboot,thirdPartyOilSmallTaskExecutor,配置,线程,executor,ThreadPoolTaskExecut From: https://www.cnblogs.com/zhuoneng/p/18282277
public class ThirdPartyOilSmallTaskConfig {
@Bean("thirdPartyOilSmallTaskExecutor")
public ThreadPoolTaskExecutor uniteOilThreadPoolTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(50);
executor.setQueueCapacity(3000);
executor.setKeepAliveSeconds(15);
executor.setThreadNamePrefix("thirdPartyOilSmallTaskExecutor-");
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
//方法用来设置 线程池关闭 的时候 等待 所有任务都完成后,再继续 销毁 其他的 Bean
executor.setWaitForTasksToCompleteOnShutdown(true);
// 该方法用来设置线程池中 任务的等待时间,如果超过这个时间还没有销毁就 强制销毁,以确保应用最后能够被关闭,而不是阻塞住
executor.setAwaitTerminationSeconds(10);
return executor;
}
}