SpringBoot是否会自动注入一个线程池

来源:10-11 使用MQ解耦点赞通知功能

此间道

2022-03-15

自动配置类TaskExecutionAutoConfiguration,创建的public ThreadPoolTaskExecutor applicationTaskExecutor,是否是默认的线程池

而且并发测试时,确实会出现有多个异步线程同时开始.


http://img.mukewang.com/szimg/6231ad0109d8524600000000.jpg

2022-03-16 17:20:01.134 [http-nio-8087-exec-1] INFO  c.s.template.controller.test.AsyncController - http-nio-8087-exec-1====end2===== 

2022-03-16 17:20:01.134 [http-nio-8087-exec-6] INFO  c.s.template.controller.test.AsyncController - http-nio-8087-exec-6====end2===== 

2022-03-16 17:20:01.134 [task-18] INFO  cj.springboot.template.service.test.CJAsyncService - task-18====start===== 

2022-03-16 17:20:01.134 [task-17] INFO  cj.springboot.template.service.test.CJAsyncService - task-17====start===== 

2022-03-16 17:20:01.134 [task-16] INFO  cj.springboot.template.service.test.CJAsyncService - task-16====start===== 


写回答

1回答

甲蛙

2022-03-15

是指异步化@Async吗?没有自动加线程池,可以自己配置一个线程池,让所有的异步线程在一个池里

下载视频          
0
2
甲蛙
回复
此间道
可以看下这篇文章:https://zhuanlan.zhihu.com/p/346086161,默认每次都会起一个新的线程,所以task后面的数字会一直加,可以通过配置一个可重复使用的池
2022-03-17
共2条回复

Spring Boot+Vue3前后端分离,实战wiki知识库系统

一课掌握前后端最火框架,更有职场竞争力

2524 学习 · 1671 问题

查看课程