feix: mail thread core should lt max

This commit is contained in:
vran 2022-04-12 10:13:37 +08:00
parent a3c0c70f46
commit 6c81603d75
1 changed files with 7 additions and 2 deletions

View File

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