From 6d99081f3f6e0363b0bd28053e545a8e4589b979 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期五, 09 一月 2026 08:50:11 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/impl/ZyRgvThread.java |   63 +++++++++++++++----------------
 1 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/impl/ZyRgvThread.java b/src/main/java/com/zy/core/thread/impl/ZyRgvThread.java
index e5c2d77..41c78fe 100644
--- a/src/main/java/com/zy/core/thread/impl/ZyRgvThread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZyRgvThread.java
@@ -40,8 +40,6 @@
     private ZyRgvConnectDriver zyRgvConnectDriver;
     private RgvProtocol rgvProtocol;
     private int deviceLogCollectTime = 200;
-    private volatile boolean closed = false;
-    private Thread mainThread;
 
     public ZyRgvThread(DeviceConfig deviceConfig, RedisUtil redisUtil) {
         this.deviceConfig = deviceConfig;
@@ -53,33 +51,39 @@
     public void run() {
         connect();
         initRgv();
-        mainThread = Thread.currentThread();
-        while (!closed && !Thread.currentThread().isInterrupted()) {
-            try {
-                deviceLogCollectTime = Utils.getDeviceLogCollectTime();
-                int step = 1;
-                Task task = MessageQueue.poll(SlaveType.Rgv, deviceConfig.getDeviceNo());
-                if (task != null) {
-                    step = task.getStep();
+
+        Thread readThread = new Thread(() -> {
+            while (true) {
+                try {
+                    deviceLogCollectTime = Utils.getDeviceLogCollectTime();
+                    readStatus();
+                    Thread.sleep(100);
+                } catch (Exception e) {
+                    log.error("RgvThread Fail", e);
                 }
-                switch (step) {
-                    case 1:
-                        readStatus();
-                        break;
-                    case 2:
-                        sendCommand((RgvCommand) task.getData());
-                        break;
-                    default:
-                        break;
-                }
-                Thread.sleep(200);
-            } catch (InterruptedException ie) {
-                Thread.currentThread().interrupt();
-                break;
-            } catch (Exception e) {
-                e.printStackTrace();
             }
-        }
+        });
+        readThread.start();
+
+        Thread processThread = new Thread(() -> {
+            while (true) {
+                try {
+                    int step = 1;
+                    Task task = MessageQueue.poll(SlaveType.Rgv, deviceConfig.getDeviceNo());
+                    if (task != null) {
+                        step = task.getStep();
+                    }
+                    if (step == 2) {
+                        sendCommand((RgvCommand) task.getData());
+                    }
+
+                    Thread.sleep(100);
+                } catch (Exception e) {
+                    log.error("RgvProcess Fail", e);
+                }
+            }
+        });
+        processThread.start();
     }
 
     private void initRgv() {
@@ -157,11 +161,6 @@
 
     @Override
     public void close() {
-        closed = true;
-        Thread t = mainThread;
-        if (t != null) {
-            try { t.interrupt(); } catch (Exception ignore) {}
-        }
         if (zyRgvConnectDriver != null) {
             zyRgvConnectDriver.close();
         }

--
Gitblit v1.9.1