修改线程池

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