From be7082f5e21aaab0ef541d9a78ced7eaebcfb1f7 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Thu, 25 Nov 2021 15:33:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=9A=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/genersoft/iot/vmp/conf/ThreadPoolTaskConfig.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 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 index 1dfd591e..2ef33230 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/ThreadPoolTaskConfig.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/ThreadPoolTaskConfig.java @@ -11,6 +11,8 @@ import java.util.concurrent.ThreadPoolExecutor; @EnableAsync(proxyTargetClass = true) public class ThreadPoolTaskConfig { + public static final int cpuNum = Runtime.getRuntime().availableProcessors(); + /** * 默认情况下,在创建了线程池后,线程池中的线程数为0,当有任务来之后,就会创建一个线程去执行任务, * 当线程池中的线程数目达到corePoolSize后,就会把到达的任务放到缓存队列当中; @@ -20,11 +22,11 @@ public class ThreadPoolTaskConfig { /** * 核心线程数(默认线程数) */ - private static final int corePoolSize = 5; + private static final int corePoolSize = cpuNum; /** * 最大线程数 */ - private static final int maxPoolSize = 30; + private static final int maxPoolSize = cpuNum*2; /** * 允许线程空闲时间(单位:默认为秒) */ @@ -32,7 +34,7 @@ public class ThreadPoolTaskConfig { /** * 缓冲队列大小 */ - private static final int queueCapacity = 10000; + private static final int queueCapacity = 500; /** * 线程池名前缀 */