Commit be7082f5e21aaab0ef541d9a78ced7eaebcfb1f7
1 parent
59e369e3
优化多线程参数
Showing
1 changed file
with
5 additions
and
3 deletions
src/main/java/com/genersoft/iot/vmp/conf/ThreadPoolTaskConfig.java
| ... | ... | @@ -11,6 +11,8 @@ import java.util.concurrent.ThreadPoolExecutor; |
| 11 | 11 | @EnableAsync(proxyTargetClass = true) |
| 12 | 12 | public class ThreadPoolTaskConfig { |
| 13 | 13 | |
| 14 | + public static final int cpuNum = Runtime.getRuntime().availableProcessors(); | |
| 15 | + | |
| 14 | 16 | /** |
| 15 | 17 | * 默认情况下,在创建了线程池后,线程池中的线程数为0,当有任务来之后,就会创建一个线程去执行任务, |
| 16 | 18 | * 当线程池中的线程数目达到corePoolSize后,就会把到达的任务放到缓存队列当中; |
| ... | ... | @@ -20,11 +22,11 @@ public class ThreadPoolTaskConfig { |
| 20 | 22 | /** |
| 21 | 23 | * 核心线程数(默认线程数) |
| 22 | 24 | */ |
| 23 | - private static final int corePoolSize = 5; | |
| 25 | + private static final int corePoolSize = cpuNum; | |
| 24 | 26 | /** |
| 25 | 27 | * 最大线程数 |
| 26 | 28 | */ |
| 27 | - private static final int maxPoolSize = 30; | |
| 29 | + private static final int maxPoolSize = cpuNum*2; | |
| 28 | 30 | /** |
| 29 | 31 | * 允许线程空闲时间(单位:默认为秒) |
| 30 | 32 | */ |
| ... | ... | @@ -32,7 +34,7 @@ public class ThreadPoolTaskConfig { |
| 32 | 34 | /** |
| 33 | 35 | * 缓冲队列大小 |
| 34 | 36 | */ |
| 35 | - private static final int queueCapacity = 10000; | |
| 37 | + private static final int queueCapacity = 500; | |
| 36 | 38 | /** |
| 37 | 39 | * 线程池名前缀 |
| 38 | 40 | */ | ... | ... |