日常提交
This commit is contained in:
18
spring/spring boot/Spring Boot Async.md
Normal file
18
spring/spring boot/Spring Boot Async.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# Spring Boot Async
|
||||
当当前上下文中没有Executor类型的bean对象时,spring boot会自动配置一个ThreadPoolTaskExecutor类型的bean对象,并且将该bean对象和异步task执行(@EnableAsync)和spring mvc异步请求处理关联在一起。
|
||||
该默认创建的ThreadPoolTaskExecutor默认使用8个核心线程,并且线程数量可以根据负载动态的增加或者减少。
|
||||
可以通过如下方式对ThreadPoolTaskExecutor进行配置:
|
||||
```properties
|
||||
# 该线程池最多含有16个线程
|
||||
spring.task.execution.pool.max-size=16
|
||||
# 有有界队列存放task,上限为100
|
||||
spring.task.execution.pool.queue-capacity=100
|
||||
# 当线程空闲10s(默认60s)时会进行回收
|
||||
spring.task.execution.pool.keep-alive=10s
|
||||
```
|
||||
如果使用@EnableScheduling,一个ThreadPoolTaskScheduler也可以被配置。该线程池默认使用一个线程,但是也可以动态设置:
|
||||
```properties
|
||||
spring.task.scheduling.thread-name-prefix=scheduling-
|
||||
spring.task.scheduling.pool.size=2
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user