修改线程池

This commit is contained in:
zren25
2025-05-27 20:06:34 +08:00
parent 4d5b76eb0f
commit 2240a8d477

View File

@@ -30,7 +30,7 @@ public class ExecutorConfig {
@Bean("threadPoolTaskExecutor") @Bean("threadPoolTaskExecutor")
@Primary @Primary
public ThreadPoolTaskExecutor corpusProcessExecutor() { public ThreadPoolTaskExecutor corpusProcessExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize); executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize); executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity); executor.setQueueCapacity(queueCapacity);
@@ -38,14 +38,13 @@ public class ExecutorConfig {
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.setKeepAliveSeconds(keepAliveSeconds); executor.setKeepAliveSeconds(keepAliveSeconds);
executor.initialize(); executor.initialize();
this.executor = executor;
return executor; return executor;
} }
@PreDestroy @PreDestroy
public void destroy() { public void destroy() {
if (executor != null) { if (executor != null) {
log.info("Shutting down thread pool: {}", executor); log.info("Thread-process-pool-ShuttingDown: {}", executor);
ThreadPoolExecutor threadPoolExecutor = this.executor.getThreadPoolExecutor(); ThreadPoolExecutor threadPoolExecutor = this.executor.getThreadPoolExecutor();
threadPoolExecutor.shutdownNow(); // 强制关闭所有正在执行的任务 threadPoolExecutor.shutdownNow(); // 强制关闭所有正在执行的任务
} }