1.修改多线程配置,修复线程不复用的问题

This commit is contained in:
2025-07-08 15:19:59 +08:00
parent 12f4059ba0
commit 7aceb760a2
7 changed files with 44 additions and 15 deletions

View File

@@ -0,0 +1,23 @@
package com.yupi.springbootinit.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
public class AsyncConfig {
@Bean
public Executor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10); // 与 yaml 保持一致
executor.setMaxPoolSize(20);
executor.setQueueCapacity(200);
executor.setThreadNamePrefix("save-task-");
executor.initialize();
return executor;
}
}