ty130316261 3 lat temu
rodzic
commit
4eb71bbf2b

+ 8 - 7
zd-modules/zd-netty/src/main/java/com/zd/netty/sdk/DeJuRFIDService.java

@@ -22,6 +22,7 @@ import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 @Slf4j
 @Service
@@ -32,7 +33,7 @@ public class DeJuRFIDService implements IService {
 
     private final Map<String, GClient> clientMap = new ConcurrentHashMap<>();
 
-    private volatile boolean isAlarm=false;
+    private final AtomicBoolean isAlarm=new AtomicBoolean();
 
     private final ScheduledExecutorService scheduledExecutorService= SpringUtils.getBean("scheduledExecutorService");
 
@@ -153,13 +154,13 @@ public class DeJuRFIDService implements IService {
         String status = state == 1 ? "start" : "stop";
         if (0 == msgAppSetGpo.getRtCode()) {
             log.info("Gpo epc {} successful.",status);
+            if (state==1){
+                stopGpo(client,delayTime);
+                isAlarm.set(false);
+            }
         } else {
             log.error("Gpo epc {} error.",status);
         }
-        if (state==1){
-            stopGpo(client,delayTime);
-            isAlarm=false;
-        }
     }
 
     public void stopGpo(GClient client,int delayTime){
@@ -181,9 +182,9 @@ public class DeJuRFIDService implements IService {
             if (logBaseEpcInfo.getResult() == 0) {
                 log.info("===========》{}",logBaseEpcInfo.getbEpc());
                 //灯带设置
-                if (!isAlarm){
+                if (!isAlarm.get()){
                     scheduledExecutorService.execute(() -> {
-                        isAlarm=true;
+                        isAlarm.set(true);
                         changeGpo(1, client,10);
                     });
                 }