1.修改多线程配置,修复线程不复用的问题
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user