feiyu02
2025-07-31 6688232eaa889eeb6c58d0d804b587699db55ec2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package cn.flightfeather.supervision.config
 
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.annotation.EnableAsync
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
import java.util.concurrent.Executor
 
 
@Configuration
@EnableAsync
class AsyncConfig {
    /*
     *此处成员变量应该使用@Value从配置中读取
    */
    private val corePoolSize = 10
    private val maxPoolSize = 200
    private val queueCapacity = 10
    @Bean
    fun taskExecutor(): Executor {
        val executor = ThreadPoolTaskExecutor()
        executor.corePoolSize = corePoolSize
        executor.maxPoolSize = maxPoolSize
        executor.setQueueCapacity(queueCapacity)
        executor.initialize()
        return executor
    }
}