Browse Source

线程采集

985653680@qq.com 1 năm trước cách đây
mục cha
commit
d0eb8fe607

+ 5 - 1
src/main/java/com/gzlh/api/OpenApi.java

@@ -18,7 +18,11 @@ public class OpenApi {
 
     @RequestMapping("test")
     public ResultJson test(){
-        eventBus.start("test","LED_SHOW_CONTENT");
+        eventBus.start("LED_SHOW_CONTENT");
+        eventBus.start("LED_SHOW_CONTENT");
+        eventBus.start("LED_SHOW_CONTENT");
+        eventBus.start("LED_SHOW_CONTENT");
+        eventBus.start("LED_SHOW_CONTENT");
         return ResultJson.success();
     }
 }

+ 2 - 14
src/main/java/com/gzlh/event/EventBus.java

@@ -1,21 +1,9 @@
 package com.gzlh.event;
 
-import cn.hutool.core.thread.ThreadUtil;
-import cn.hutool.core.util.NumberUtil;
-import cn.hutool.core.util.RandomUtil;
-import cn.hutool.core.util.StrUtil;
-import com.gzlh.config.ModuleEnum;
 import com.gzlh.dto.EventDTO;
-import com.gzlh.led.factory.LedFactory;
-import com.gzlh.led.properties.LedPropertiesConfig;
-import com.gzlh.infrared.config.RedPropertiesConfig;
-import com.gzlh.infrared.factory.RedFactory;
-import com.gzlh.weighbridge.config.WeighbridgePropertiesConfig;
-import com.gzlh.weighbridge.factory.WeighbridgeFactory;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
-import javax.annotation.Resource;
 import java.util.List;
 
 @Component
@@ -27,8 +15,8 @@ public class EventBus {
         this.eventDTOList = eventDTOList;
     }
 
-    public void start(String name,String eventName){
-        EventThread thread = new EventThread(name,eventName);
+    public void start(String eventName){
+        EventThread thread = new EventThread(eventName);
         thread.setEventDTOList(eventDTOList);
         thread.start();
     }

+ 3 - 6
src/main/java/com/gzlh/event/EventThread.java

@@ -15,6 +15,7 @@ import com.gzlh.weighbridge.factory.WeighbridgeFactory;
 import lombok.extern.slf4j.Slf4j;
 
 import javax.annotation.Resource;
+import java.util.Date;
 import java.util.List;
 
 @Slf4j
@@ -38,8 +39,8 @@ public class EventThread extends Thread{
     public EventThread() {
     }
 
-    public EventThread(String name, String eventName) {
-        this.setName(name+"-"+ RandomUtil.randomNumber());
+    public EventThread(String eventName) {
+        this.setName(eventName);
         this.eventName=eventName;
     }
 
@@ -56,11 +57,9 @@ public class EventThread extends Thread{
      */
     public void handlerEvent(String eventName) {
         log.info("event:{}", eventName);
-        System.out.println(eventName);
 
         eventDTOList.stream().filter(eventDTO -> StrUtil.equals(eventName, eventDTO.getName()))
                 .findFirst().ifPresent(eventDTO -> {
-            System.out.println(eventDTO);
 
             List<String> actionList = eventDTO.getActionList().getAction();
             //依次执行动作
@@ -107,8 +106,6 @@ public class EventThread extends Thread{
     }
 
     public void run(){
-        System.out.println("thread开始");
         handlerEvent(eventName);
-        System.out.println("thread结束");
     }
 }

+ 1 - 2
src/main/java/com/gzlh/infrared/handler/impl/RedHandlerSoarDAM0404.java

@@ -49,8 +49,7 @@ public class RedHandlerSoarDAM0404 implements IRedHandler {
         }else if (StrUtil.equals(StrUtil.replace(FIRST_LINK_SIGNAL, " ", ""), content)){
             EventBus eventBus= SpringUtil.getBean(EventBus.class);
 //            //入红外被挡住
-//            eventBus.handlerEvent(ModuleEnum.INFRARED_MODULE.getModuleEn()+"."+ InfraredAction.IN_BREAK);
-            eventBus.start(ModuleEnum.INFRARED_MODULE.getModuleEn(),ModuleEnum.INFRARED_MODULE.getModuleEn()+"."+ InfraredAction.IN_BREAK);
+            eventBus.start(ModuleEnum.INFRARED_MODULE.getModuleEn()+"."+ InfraredAction.IN_BREAK);
         }
     }
 

+ 1 - 1
src/main/java/com/gzlh/weighbridge/handler/impl/CommonWeighbridgeHandler.java

@@ -62,7 +62,7 @@ public class CommonWeighbridgeHandler {
             if (averaWeight == 0 || weighbridgePropertiesConfig.getMinKg() > averaWeight) {
                 //todo read timeout
                 //读取超时
-                eventBus.start(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn(),ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.TIMEOUT);
+                eventBus.start(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.TIMEOUT);
                 return;
             }
             isStart=false;