6 changed files with 13 additions and 77 deletions
@ -1,41 +0,0 @@ |
|||
package com.project.information.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; |
|||
import java.util.concurrent.ThreadPoolExecutor; |
|||
|
|||
/** |
|||
* 异步配置类:开启异步支持 |
|||
*/ |
|||
@Configuration |
|||
@EnableAsync |
|||
public class InformationAsyncConfig { |
|||
|
|||
/** |
|||
* 自定义发生通知异步线程池 |
|||
*/ |
|||
@Bean(name = "parseExecutor") |
|||
public Executor parseExecutor() { |
|||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
|||
// 核心线程数(根据业务量调整)
|
|||
executor.setCorePoolSize(5); |
|||
// 最大线程数
|
|||
executor.setMaxPoolSize(10); |
|||
// 队列容量
|
|||
executor.setQueueCapacity(100); |
|||
// 线程前缀名(便于日志排查)
|
|||
executor.setThreadNamePrefix("parse-file-"); |
|||
// 线程空闲超时时间
|
|||
executor.setKeepAliveSeconds(60); |
|||
// 拒绝策略:队列满时由调用线程执行
|
|||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); |
|||
// 初始化线程池
|
|||
executor.initialize(); |
|||
return executor; |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue