【springboot】@Async线程默认配置

@Async异步方法默认使用Spring创建ThreadPoolTaskExecutor。默认核心线程数:8,最大线程数:Integet.MAX_VALUE,队列使用LinkedBlockingQueue,容量是:Integet.MAX_VALUE,空闲线程保留时间:60s,线程池拒绝策略:AbortPolicy。

可以手动配置相应属性:

#核心线程数
spring.task.execution.pool.core-size=200 #最大线程数
spring
.task.execution.pool.max-size=1000 #空闲线程保留时间
spring
.task.execution.pool.keep-alive=3s #队列容量
spring
.task.execution.pool.queue-capacity=1000 #线程名称前缀
spring
.task.execution.thread-name-prefix=test-thread-

配置类是TaskExecutionProperties【org.springframework.boot.autoconfigure.task.TaskExecutionProperties】

参考地址

SpringBoot项目中@Async方法没有执行的问题分析 : https://www.cnblogs.com/hepengju/p/12715034.html 

Spring Boot教程(21) – 默认线程池 : https://zhuanlan.zhihu.com/p/85855282

原文地址:https://www.cnblogs.com/kiko2014551511/p/12754927.html