线程池
public class ThreadLocalConfig {
/*
返回实例对象
*/
@Bean(value = "applicationReportThreadPool")
public Executor taskExecutor() {
ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("applicationDemo-thread-%d").build();
return new ThreadPoolExecutor(
/* 核心线程数 */
5,
/*
最大核心线程数
*/
20,
/*
队列容量
*/
15,
/*
时间单位
*/
TimeUnit.MINUTES,
/*
队列
*/
new ArrayBlockingQueue<>(500),
/*
线程工厂
*/
threadFactory,
/*
放弃政策
*/
new ThreadPoolExecutor.AbortPolicy()
);
}
@Bean
public Executor getSecondExecutorThread() {
ThreadFactory threadFactory = new ThreadFactoryBuilder().build();
return new ThreadPoolExecutor(
5,
15,
60,
TimeUnit.MINUTES,
new ArrayBlockingQueue<>(500),
threadFactory,
new ThreadPoolExecutor.AbortPolicy()
);
}
}```