refactor: 修改异步方法的配置

This commit is contained in:
Captain.B 2021-07-15 13:49:09 +08:00 committed by 刘瑞斌
parent 591a3836b4
commit 3229773d6e
2 changed files with 5 additions and 5 deletions

View File

@ -10,7 +10,6 @@ import org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication(exclude = { @SpringBootApplication(exclude = {
@ -24,7 +23,6 @@ import org.springframework.scheduling.annotation.EnableScheduling;
JmeterProperties.class JmeterProperties.class
}) })
@EnableScheduling @EnableScheduling
@EnableAsync(proxyTargetClass = true)
//@PropertySource(value = {"file:c:\\opt\\metersphere\\conf\\metersphere.properties"}, encoding = "UTF-8", ignoreResourceNotFound = true) //@PropertySource(value = {"file:c:\\opt\\metersphere\\conf\\metersphere.properties"}, encoding = "UTF-8", ignoreResourceNotFound = true)
@PropertySource(value = {"file:/opt/metersphere/conf/metersphere.properties"}, encoding = "UTF-8", ignoreResourceNotFound = true) @PropertySource(value = {"file:/opt/metersphere/conf/metersphere.properties"}, encoding = "UTF-8", ignoreResourceNotFound = true)
public class Application { public class Application {

View File

@ -6,6 +6,8 @@ import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ThreadPoolExecutor;
@EnableAsync(proxyTargetClass = true) @EnableAsync(proxyTargetClass = true)
@Configuration @Configuration
public class AsyncConfig { public class AsyncConfig {
@ -13,9 +15,9 @@ public class AsyncConfig {
@Bean @Bean
public AsyncTaskExecutor taskExecutor() { public AsyncTaskExecutor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setThreadNamePrefix("Async-Executor"); executor.setThreadNamePrefix("Async-Executor-");
executor.setCorePoolSize(5); executor.setCorePoolSize(10);
executor.setMaxPoolSize(10); executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
return executor; return executor;
} }
} }