zoukankan      html  css  js  c++  java
  • 异步线程池

    项目问题:

    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;
        }
    
    }
  • 相关阅读:
    什么是IO多路复用
    Coursera, Machine Learning, Unsupervised Learning, K-means, Dimentionality Reduction
    Coursera, Machine Learning, SVM
    ShareSDK
    iOS JS和OC交互
    iOS KVO 常见错误
    第三方框架之SDWebImage
    单例存储账号
    UIRefreshControl
    二维码扫描
  • 原文地址:https://www.cnblogs.com/wangymd/p/11490507.html
Copyright © 2011-2022 走看看