• 线程池配置


    yml:文件

     创建一个spring 线程池配置类

    @EnableAsync
    @Configuration
    public class ThreadPoolConfig {
        private static Logger logger = LoggerFactory.getLogger(ThreadPoolConfig.class);
    
        @Value("${threadpool.core-pool-size}")
        private int corePoolSize;
    
        @Value("${threadpool.max-pool-size}")
        private int maxPoolSize;
    
        @Value("${threadpool.queue-capacity}")
        private int queueCapacity;
    
        @Value("${threadpool.keep-alive-seconds}")
        private int keepAliveSeconds;
    
    
        @Bean(name = "asyncServiceExecutor")
        public Executor asyncServiceExecutor() {
            logger.info("start executor -->");
            ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
            //设置核心线程数
            executor.setCorePoolSize(corePoolSize);
            //设置最大线程数
            executor.setMaxPoolSize(maxPoolSize);
            //设置队列大小
            executor.setQueueCapacity(queueCapacity);
            //配置线程池的前缀
            executor.setThreadNamePrefix("async-plan-service-");
            executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
            //设置空闲时间
            executor.setKeepAliveSeconds(keepAliveSeconds);
            //进行加载
            executor.initialize();
            return executor;
        }
    }
  • 相关阅读:
    闭包
    iframe
    函数声明和函数表达式
    简单的事件委托
    onhashchange
    WebP探索
    Chrome
    适合自己学习的一些网站
    模拟jQuery的一些功能
    __autoload()方法
  • 原文地址:https://www.cnblogs.com/zrboke/p/15184813.html
Copyright © 2020-2023  润新知