feix: mail thread core should lt max
This commit is contained in:
parent
a3c0c70f46
commit
6c81603d75
|
@ -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…
Reference in New Issue