日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

线程池的配置说明

發(fā)布時間:2025/3/21 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 线程池的配置说明 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
application:config:threadpool:ExecutorPool:corePoolSize: 16maxPoolSize: 64queueCapacity: 128

使用類取繼承該類指向的線程池:

@Override
public void afterPropertiesSet() throws Exception {
executor = applicationThreadPoolFactory.newExecutor("ExecutorPool");
} @Resourceprivate ConfigReader configReader;@Resourceprivate 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;} //獲取環(huán)境變量配置的類
public
class ConfigReader {public static final String PREDIX = "application.config";@Resourceprivate 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);} }

?

轉載于:https://www.cnblogs.com/otways/p/11196693.html

《新程序員》:云原生和全面數(shù)字化實踐50位技術專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的线程池的配置说明的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。