zoukankan      html  css  js  c++  java
  • 线程池的配置说明

    application:
      config:
        threadpool:
          ExecutorPool:
            corePoolSize: 16
            maxPoolSize: 64
            queueCapacity: 128

    使用类取继承该类指向的线程池:

    @Override
    public void afterPropertiesSet() throws Exception {
    executor = applicationThreadPoolFactory.newExecutor("ExecutorPool");
    }
    @Resource
        private ConfigReader configReader;
        
        @Resource
        private TransactionRejectedExecutionHandler rejectedHandler;
        
        public ApplicationThreadPoolConfig getPoolConfig(String namePrefix){
            Integer corePoolSize = configReader.getProperty("threadpool."+namePrefix, "corePoolSize", Integer.class, 20);
            Integer maxPoolSize = configReader.getProperty("threadpool."+namePrefix, "maxPoolSize", Integer.class, 40);
            Integer queueCapacity = configReader.getProperty("threadpool."+namePrefix, "queueCapacity", Integer.class, 10);
            looger.info("##ThreadPoll -- Config: {}; corePoolSize={}", namePrefix, corePoolSize);
            looger.info("##ThreadPoll -- Config: {}; maxPoolSize={}", namePrefix, maxPoolSize);
            looger.info("##ThreadPoll -- Config: {}; queueCapacity={}", namePrefix, queueCapacity);
            ApplicationThreadPoolConfig config = new ApplicationThreadPoolConfig();
            config.setCorePoolSize(corePoolSize);
            config.setMaxPoolSize(maxPoolSize);
            config.setQueueCapacity(queueCapacity);
            return config;
        }
        
        
        public Executor newExecutor(String namePrefix, int corePoolSize, int maxPoolSize, int queuedSize) {
            ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
            executor.setCorePoolSize(corePoolSize);
            executor.setMaxPoolSize(maxPoolSize);
            executor.setQueueCapacity(queuedSize);
            executor.setThreadNamePrefix(namePrefix);
            executor.setRejectedExecutionHandler(rejectedHandler);
            executor.initialize();
            return executor;
        }
    
        public Executor newExecutor(String namePrefix) {
            ApplicationThreadPoolConfig poolConfig = getPoolConfig(namePrefix);
            ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
            executor.setCorePoolSize(poolConfig.getCorePoolSize());
            executor.setMaxPoolSize(poolConfig.getMaxPoolSize());
            executor.setQueueCapacity(poolConfig.getQueueCapacity());
            executor.setThreadNamePrefix(namePrefix);
            executor.setRejectedExecutionHandler(rejectedHandler);
            executor.initialize();
            return executor;
        }
    //获取环境变量配置的类
    public
    class ConfigReader { public static final String PREDIX = "application.config"; @Resource private Environment env; public String getProperty (String scope, String key) { key = Strings.join(new String[]{PREDIX, scope, key}, "."); return env.getProperty(key); } public String getRequiredProperty (String scope, String key) { key = Strings.join(new String[]{PREDIX, scope, key}, "."); return env.getRequiredProperty(key); } public String getProperty (String scope, String key, String defaultValue) { key = Strings.join(new String[]{PREDIX, scope, key}, "."); return env.getProperty(key, defaultValue); } public <T> T getProperty (String scope, String key, Class<T> targetType, T defaultValue) { key = Strings.join(new String[]{PREDIX, scope, key}, "."); return env.getProperty(key, targetType, defaultValue); } public <T> T getRequiredProperty (String scope, String key, Class<T> targetType, T defaultValue) { key = Strings.join(new String[]{PREDIX, scope, key}, "."); return env.getProperty(key, targetType, defaultValue); } }
  • 相关阅读:
    oc之数组反序输出示例
    OC--有这么一个 整数 123456789,如何将这个整数的每一位数,从末位开始依次放入数组中,并遍历 倒序输出字符串
    oc--截取字符串(从网址中截取用户名和密码)
    iOS 第七期考核题(字符串以及字典的使用 数组内容转换成字符串)
    iOS 第六期考核题(字典的使用)
    iOS 第五期考核题(字典与数组嵌套,字典的排序/删除)
    Linux服务启动报错日志分析
    新手Linux命令-1
    新手Linux命令-2
    计划任务服务
  • 原文地址:https://www.cnblogs.com/otways/p/11196693.html
Copyright © 2011-2022 走看看