diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/MafAutoConfiguration.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/MafAutoConfiguration.java index e857c67c..ca30453a 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/MafAutoConfiguration.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/MafAutoConfiguration.java @@ -27,13 +27,11 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.servlet.error.ErrorAttributes; import org.springframework.boot.web.servlet.error.ErrorController; -import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.core.env.Environment; import org.springframework.integration.annotation.IntegrationComponentScan; -import org.springframework.web.client.RestTemplate; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import javax.annotation.PostConstruct; @@ -56,7 +54,8 @@ Swagger2Configuration.class, SftpConfiguration.class, WebSecurityConfiguration.class, - RestTemplateConfiguration.class + RestTemplateConfiguration.class, + AsyncConfiguration.class }) public class MafAutoConfiguration { @PostConstruct diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/AsyncConfiguration.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/AsyncConfiguration.java new file mode 100644 index 00000000..3c0a57a3 --- /dev/null +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/AsyncConfiguration.java @@ -0,0 +1,39 @@ +package com.jmsoftware.maf.springbootstarter.configuration; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.task.AsyncTaskExecutor; +import org.springframework.scheduling.annotation.AsyncConfigurer; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +/** + * Description: AsyncConfiguration, change description here. + * + * @author 钟俊(zhongjun), email: zhongjun@toguide.cn, date: 1/29/2021 4:39 PM + **/ +@Slf4j +@EnableAsync +@Configuration +@RequiredArgsConstructor +public class AsyncConfiguration implements AsyncConfigurer { + @Bean + @Override + public AsyncTaskExecutor getAsyncExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2); + executor.setMaxPoolSize(100); + executor.setBeanName("spring-boot-starter-thread-pool-task-executor"); + // Specify the RejectedExecutionHandler to use for the ExecutorService. + // Default is the ExecutorService's default abort policy. + executor.setRejectedExecutionHandler((runnable, executor1) -> { + log.error("Captured rejected execution. {}", runnable); + // TODO: runnable persistence + }); + executor.initialize(); + log.warn("Initial bean: '{}'", AsyncTaskExecutor.class.getSimpleName()); + return executor; + } +}