Pre Merge pull request !1076 from 秋日/master
commit
ff1e5a787f
|
|
@ -18,16 +18,18 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||
public class ThreadPoolConfig
|
||||
{
|
||||
// 核心线程池大小
|
||||
private int corePoolSize = 50;
|
||||
private int corePoolSize = Runtime.getRuntime().availableProcessors() * 2;
|
||||
|
||||
// 最大可创建的线程数
|
||||
private int maxPoolSize = 200;
|
||||
private int maxPoolSize = Runtime.getRuntime().availableProcessors() * 4;
|
||||
|
||||
// 队列最大长度
|
||||
private int queueCapacity = 1000;
|
||||
private int queueCapacity = 5000;
|
||||
|
||||
// 线程池维护线程所允许的空闲时间
|
||||
private int keepAliveSeconds = 300;
|
||||
private int keepAliveSeconds = 60;
|
||||
|
||||
private int awaitTerminationMillis = 60;
|
||||
|
||||
@Bean(name = "threadPoolTaskExecutor")
|
||||
public ThreadPoolTaskExecutor threadPoolTaskExecutor()
|
||||
|
|
@ -37,6 +39,10 @@ public class ThreadPoolConfig
|
|||
executor.setCorePoolSize(corePoolSize);
|
||||
executor.setQueueCapacity(queueCapacity);
|
||||
executor.setKeepAliveSeconds(keepAliveSeconds);
|
||||
//设置线程池关闭的时候等待所有任务都完成再继续销毁其他的Bean
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
//设置线程池中任务的等待时间,如果超过这个时候还没有销毁就强制销毁,以确保应用最后能够被关闭,而不是阻塞住
|
||||
executor.setAwaitTerminationSeconds(awaitTerminationMillis);
|
||||
// 线程池对拒绝任务(无线程可用)的处理策略
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
return executor;
|
||||
|
|
|
|||
Loading…
Reference in New Issue