From 0f81ff5bb151d470734eaa2d7bfc7b9ffe4a4eab Mon Sep 17 00:00:00 2001
From: whyclxw <http://whyclxw@118.89.139.230:10101/r/~whyclxw/IdeaTest.git>
Date: 星期二, 08 二月 2022 17:21:12 +0800
Subject: [PATCH] 在线监测-实时监控-websocket

---
 src/main/java/com/whyc/webSocket/RealTimeWebsocket.java |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/whyc/webSocket/RealTimeWebsocket.java b/src/main/java/com/whyc/webSocket/RealTimeWebsocket.java
index 3f59245..8d7f48d 100644
--- a/src/main/java/com/whyc/webSocket/RealTimeWebsocket.java
+++ b/src/main/java/com/whyc/webSocket/RealTimeWebsocket.java
@@ -7,6 +7,7 @@
 import javax.websocket.*;
 import javax.websocket.server.ServerEndpoint;
 import java.io.IOException;
+import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -16,6 +17,8 @@
     private volatile Thread thread;
 
     private static final int executeTime = 5000;
+
+    private static boolean exit=false;
 
     private static Map<String,Thread> threadMap = new HashMap<>();
 
@@ -38,16 +41,18 @@
         Thread threadBefore = threadMap.get(session.getId());
         if(threadBefore !=null && threadBefore.isAlive()){
             threadBefore.interrupt();
+            exit=true;
         }
         thread = new Thread("Thread_RealTime") {
             public void run() {
-                while (!thread.isInterrupted()) {
+                exit=false;
+                while ( !thread.isInterrupted()&&!exit) {
                     try {
                         if (session.isOpen()) {
                             session.getBasicRemote().sendObject(service.serchByCondition(Integer.valueOf(battGroupId)));
                         }
                         sleep(executeTime);
-                    } catch (IOException | InterruptedException | EncodeException e) {
+                    } catch ( IOException | InterruptedException | EncodeException e ) {
                         interrupt();
                     }
                 }

--
Gitblit v1.9.1