Browse Source

feix: mail thread core should lt max (#82)

master
vran 3 years ago
committed by GitHub
parent
commit
0a34e3a98b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      core/src/main/java/com/databasir/core/config/AsyncConfig.java

9
core/src/main/java/com/databasir/core/config/AsyncConfig.java

@ -8,6 +8,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
@EnableAsync @EnableAsync
@Configuration @Configuration
@ -16,11 +17,15 @@ public class AsyncConfig implements AsyncConfigurer {
@Bean @Bean
public Executor mailThreadPoolTaskExecutor() { public Executor mailThreadPoolTaskExecutor() {
final int maxCorePoolSize = 16;
final int maxPoolSize = 32;
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
int availableProcessorCount = Runtime.getRuntime().availableProcessors(); int availableProcessorCount = Runtime.getRuntime().availableProcessors();
executor.setCorePoolSize(availableProcessorCount << 1); int corePoolSize = Math.min(maxCorePoolSize, availableProcessorCount);
executor.setMaxPoolSize(32); executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setAllowCoreThreadTimeOut(true); executor.setAllowCoreThreadTimeOut(true);
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
return executor; return executor;
} }
} }

Loading…
Cancel
Save