feix: mail thread core should lt max (#82)
This commit is contained in:
parent
a3c0c70f46
commit
0a34e3a98b
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue