@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