|
@@ -55,7 +55,9 @@ public class MyThreadPool extends ThreadPoolTaskExecutor {
|
|
threadPoolTaskExecutor.setKeepAliveSeconds(SystemConstant.THREAD_POOL_KEEP_ALIVE_SECONDS);//线程空闲时间
|
|
threadPoolTaskExecutor.setKeepAliveSeconds(SystemConstant.THREAD_POOL_KEEP_ALIVE_SECONDS);//线程空闲时间
|
|
threadPoolTaskExecutor.setQueueCapacity(SystemConstant.THREAD_POOL_QUEUE_CAPACITY);//队列容量
|
|
threadPoolTaskExecutor.setQueueCapacity(SystemConstant.THREAD_POOL_QUEUE_CAPACITY);//队列容量
|
|
threadPoolTaskExecutor.setThreadNamePrefix(SystemConstant.THREAD_POOL_NAME);
|
|
threadPoolTaskExecutor.setThreadNamePrefix(SystemConstant.THREAD_POOL_NAME);
|
|
- threadPoolTaskExecutor.setAllowCoreThreadTimeOut(true);
|
|
|
|
|
|
+ threadPoolTaskExecutor.setAllowCoreThreadTimeOut(true);//设置是否允许核心线程超时。若允许,核心线程超时后,会被销毁。默认为不允许(fasle)
|
|
|
|
+ threadPoolTaskExecutor.setWaitForTasksToCompleteOnShutdown(true);//设置shutdown时是否等到所有任务完成再真正关闭
|
|
|
|
+ threadPoolTaskExecutor.setAwaitTerminationSeconds(60);//当setWaitForTasksToCompleteOnShutdown(true)时,setAwaitTerminationSeconds 设置在 shutdown 之后最多等待多长时间后再真正关闭线程池
|
|
// rejection-policy:当pool已经达到max size的时候,如何处理新任务
|
|
// rejection-policy:当pool已经达到max size的时候,如何处理新任务
|
|
// CALLER_RUNS:不在新线程中执行任务,而是由调用者所在的线程来执行
|
|
// CALLER_RUNS:不在新线程中执行任务,而是由调用者所在的线程来执行
|
|
threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
|
threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|