• 线程池--配置和在spring中使用,@PropertySource读取配置文件


    1.注入到容器中

    /**
     * 线程池配置
     *
     * @date 2019年02月27日
     */
    @Configuration
    @PropertySource("classpath:/threadpool.properties")
    public class ExecutePoolConfiguration {
        private static final Logger logger = LoggerFactory.getLogger(ExecutePoolConfiguration.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 = "threadPoolTaskExecutor")
        public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
            ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
            pool.setKeepAliveSeconds(keepAliveSeconds);
            // 核心线程池数
            pool.setCorePoolSize(corePoolSize);
            // 最大线程
            pool.setMaxPoolSize(maxPoolSize);
            // 队列容量
            pool.setQueueCapacity(queueCapacity);
            // 队列满,线程被拒绝执行策略
            pool.setRejectedExecutionHandler(new java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy());
            return pool;
        }
    }
    

    2.使用

        @Autowired
        ThreadPoolTaskExecutor threadPoolTaskExecutor;
    
        threadPoolTaskExecutor.execute(new SaveLogThread(sysLog, sysLogService));
    
  • 相关阅读:
    Flowplayer-Subtitle
    Flowplayer-playlist
    Flowplayer-Embedding
    Flowplayer-Skin
    Flowplayer-Setup
    Flowplayer-JavaScript API
    任务监控程序设计与实现总结
    Spark RDD整理
    oracle连接和执行流程总结
    阅读《Oracle内核技术揭秘》的读书笔记
  • 原文地址:https://www.cnblogs.com/kltsee/p/13949128.html
Copyright © 2020-2023  润新知