李进 2 лет назад
Родитель
Сommit
28654f7e0e

+ 5 - 12
device-api-service/src/main/java/com/xy/config/DeviceThreadPoolConfig.java

@@ -1,7 +1,6 @@
 package com.xy.config;
 
 import com.dtp.core.support.DynamicTp;
-import com.xy.error.CommRuntimeException;
 import com.xy.utils.ThreadPoolUtils;
 import org.springframework.context.annotation.Bean;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@@ -42,12 +41,9 @@ public class DeviceThreadPoolConfig {
         return ThreadPoolUtils.newPoll()
                 .name(DEVICE_DATA_POLL)
                 .coreSize(coreSize)
-                .maxSize(coreSize * 2)
-                .keepAlive(60)
+                .maxSize(coreSize * 10)
+                .keepAlive(30)
                 .queueSize(coreSize * 10)
-                .rejected((r, executor) -> {
-                    throw new CommRuntimeException("统计消费者线程池已满");
-                })
                 .builder();
     }
 
@@ -57,16 +53,13 @@ public class DeviceThreadPoolConfig {
     @DynamicTp
     @Bean(DEVICE_NETWORK_POLL)
     public ThreadPoolTaskExecutor deviceNetWorkPoll() {
-        int coreSize = 20;
+        int coreSize = 5;
         return ThreadPoolUtils.newPoll()
                 .name(DEVICE_NETWORK_POLL)
                 .coreSize(coreSize)
-                .maxSize(coreSize * 2)
-                .keepAlive(60)
+                .maxSize(coreSize * 10)
+                .keepAlive(30)
                 .queueSize(coreSize * 10)
-                .rejected((r, executor) -> {
-                    throw new CommRuntimeException("设备上下线消费者线程池已满");
-                })
                 .builder();
     }
 }

+ 2 - 2
device-api-service/src/main/java/com/xy/consumer/data/DataConsumer.java

@@ -32,10 +32,10 @@ public class DataConsumer implements MqttConsumer {
 
     @Override
     public boolean message(String topic, String payload) {
-        JSONObject jsonObject = JSONUtil.parseObj(payload);
-        DataMqttVo dataMqttVo = jsonObject.toBean(DataMqttVo.class);
         ThreadPoolUtils.excPoll(DeviceThreadPoolConfig.DEVICE_DATA_POLL, 1)
                 .execute(() -> {
+                    JSONObject jsonObject = JSONUtil.parseObj(payload);
+                    DataMqttVo dataMqttVo = jsonObject.toBean(DataMqttVo.class);
                     Boolean type = dataMqttVo.getType();
                     List<DataMqttVo.Goods> goods = dataMqttVo.getGoods();
                     Integer money = dataMqttVo.getMoney();