【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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM