2种自定义线程池的区别
来源:7-9 功能服务接口定义(2)

慕运维0184815
2019-12-05
老师,你好:
自定义异步线程池时: 下面2种方式哪个更优?有什么区别?
- 重写springBoot默认线程池, 实现 AsyncConfiger
- 自定义线程池配置类
@Configuration
public class PoolConfig {
@Bean
public Executor testExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(20);
executor.setQueueCapacity(20);
executor.setKeepAliveSeconds(60);
executor.setThreadNamePrefix("ImoocAsync_");
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
return executor;
}
}
写回答
1回答
-
张勤一
2019-12-05
同学你好:
这两种方式没有本质的区别,因为异步线程池的实现 SpringBoot 中肯定只有一套。所以,使用你熟悉或者简单的方式实现就是最好的。
欢迎来 QQ 群随时交流、讨论,也非常感谢同学的支持!
20
相似问题