whyclxw
2022-02-08 0f81ff5bb151d470734eaa2d7bfc7b9ffe4a4eab
在线监测-实时监控-websocket
1个文件已修改
9 ■■■■ 已修改文件
src/main/java/com/whyc/webSocket/RealTimeWebsocket.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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();
                    }
                }