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