异步线程池
Posted wangymd
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了异步线程池相关的知识,希望对你有一定的参考价值。
项目问题:
Caused by: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@326c8e82 rejected from java.util.concurrent.ThreadPoolExecutor@6e5c35b6[Running, pool size = 200, active threads = 200, queued tasks = 50, completed tasks = 1886]
package cn.async; import java.util.concurrent.Executor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.AsyncConfigurer; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; /** * 异步线程池配置类 * @author wangymd * */ @Configuration public class AsyncConfig implements AsyncConfigurer private Log log = LogFactory.getLog(AsyncConfig.class); @Override @Bean(name = "asyncExecutor") public Executor getAsyncExecutor() log.info("线程池初始化。。。"); //定义线程池 ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); //核心线程数 taskExecutor.setCorePoolSize(50); //线程池最大线程数 taskExecutor.setMaxPoolSize(200); //线程队列最大线程数 taskExecutor.setQueueCapacity(500); //初始化 taskExecutor.initialize(); return taskExecutor; @Override public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() // TODO Auto-generated method stub return null;
以上是关于异步线程池的主要内容,如果未能解决你的问题,请参考以下文章