From 6ac131bcf6ec034ffc9e5813c68c56c6e5c32b70 Mon Sep 17 00:00:00 2001 From: xiaoxie <hotcoffie@163.com> Date: 星期三, 01 十二月 2021 22:45:51 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/wvp-28181-2.0' into wvp-28181-2.0 --- src/main/java/com/genersoft/iot/vmp/conf/ThreadPoolTaskConfig.java | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 59 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/conf/ThreadPoolTaskConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/ThreadPoolTaskConfig.java new file mode 100644 index 0000000..2ef3323 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/conf/ThreadPoolTaskConfig.java @@ -0,0 +1,59 @@ +package com.genersoft.iot.vmp.conf; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +import java.util.concurrent.ThreadPoolExecutor; + +@Configuration +@EnableAsync(proxyTargetClass = true) +public class ThreadPoolTaskConfig { + + public static final int cpuNum = Runtime.getRuntime().availableProcessors(); + + /** + * 榛樿鎯呭喌涓嬶紝鍦ㄥ垱寤轰簡绾跨▼姹犲悗锛岀嚎绋嬫睜涓殑绾跨▼鏁颁负0锛屽綋鏈変换鍔℃潵涔嬪悗锛屽氨浼氬垱寤轰竴涓嚎绋嬪幓鎵ц浠诲姟锛� + * 褰撶嚎绋嬫睜涓殑绾跨▼鏁扮洰杈惧埌corePoolSize鍚庯紝灏变細鎶婂埌杈剧殑浠诲姟鏀惧埌缂撳瓨闃熷垪褰撲腑锛� + * 褰撻槦鍒楁弧浜嗭紝灏辩户缁垱寤虹嚎绋嬶紝褰撶嚎绋嬫暟閲忓ぇ浜庣瓑浜巑axPoolSize鍚庯紝寮�濮嬩娇鐢ㄦ嫆缁濈瓥鐣ユ嫆缁� + */ + + /** + * 鏍稿績绾跨▼鏁帮紙榛樿绾跨▼鏁帮級 + */ + private static final int corePoolSize = cpuNum; + /** + * 鏈�澶х嚎绋嬫暟 + */ + private static final int maxPoolSize = cpuNum*2; + /** + * 鍏佽绾跨▼绌洪棽鏃堕棿锛堝崟浣嶏細榛樿涓虹锛� + */ + private static final int keepAliveTime = 30; + /** + * 缂撳啿闃熷垪澶у皬 + */ + private static final int queueCapacity = 500; + /** + * 绾跨▼姹犲悕鍓嶇紑 + */ + private static final String threadNamePrefix = "wvp-sip-handle-"; + + @Bean("taskExecutor") // bean鐨勫悕绉帮紝榛樿涓洪瀛楁瘝灏忓啓鐨勬柟娉曞悕 + public ThreadPoolTaskExecutor taskExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(corePoolSize); + executor.setMaxPoolSize(maxPoolSize); + executor.setQueueCapacity(queueCapacity); + executor.setKeepAliveSeconds(keepAliveTime); + executor.setThreadNamePrefix(threadNamePrefix); + + // 绾跨▼姹犲鎷掔粷浠诲姟鐨勫鐞嗙瓥鐣� + // CallerRunsPolicy锛氱敱璋冪敤绾跨▼锛堟彁浜や换鍔$殑绾跨▼锛夊鐞嗚浠诲姟 + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + // 鍒濆鍖� + executor.initialize(); + return executor; + } +} -- Gitblit v1.8.0