• 异步线程池


    项目问题:

    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;
        }
    
    }
  • 相关阅读:
    公司-科技-电商:京东
    公司-科技-协调:泛微
    公司-科技-财务:新中大
    公司-科技-财务:金蝶
    公司-科技-财务:用友
    公司-科技:SAMSUNG
    杂项-公司:华为
    “莆田系”到底是个什么玩意儿?
    Java 虚拟机是如何判定两个 Java 类是相同的?
    java类加载器是什么?
  • 原文地址:https://www.cnblogs.com/wangymd/p/11490507.html
Copyright © 2020-2023  润新知