build: 启用异步机制

This commit is contained in:
CaptainB 2023-10-31 15:10:06 +08:00 committed by 刘瑞斌
parent fdbd90c8a0
commit fc63fa5bc1
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package io.metersphere.system.config;
import org.springframework.context.annotation.Bean;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ThreadPoolExecutor;
@EnableAsync(proxyTargetClass = true)
public class AsyncConfig {
@Bean
public AsyncTaskExecutor asyncTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setThreadNamePrefix("Async-Executor-");
executor.setCorePoolSize(5);
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
return executor;
}
}