From 3e3c10fa9d1e4a4b01bbbb51884621da40056d30 Mon Sep 17 00:00:00 2001 From: Odboy Date: Thu, 30 Oct 2025 23:06:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor(websocket):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=BA=BF=E7=A8=8B=E7=AE=A1=E7=90=86=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../websocket/context/CsWsServer.java | 29 ----------------- .../websocket/context/CsWsServer.java | 31 +------------------ 2 files changed, 1 insertion(+), 59 deletions(-) diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/websocket/context/CsWsServer.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/websocket/context/CsWsServer.java index bfc64448..716fce70 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/websocket/context/CsWsServer.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/websocket/context/CsWsServer.java @@ -25,16 +25,13 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import java.io.IOException; -import java.util.Map; import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; @Slf4j @Component @ServerEndpoint("/websocket/{sid}") @Getter public class CsWsServer { - private static final Map taskThreadMap = new ConcurrentHashMap<>(); /** * 与某个客户端的连接会话, 需要通过它来给客户端发送数据 */ @@ -146,30 +143,4 @@ public class CsWsServer { public int hashCode() { return Objects.hash(session, sid); } - - public Thread getTaskThread(String sid) { - Thread thread = taskThreadMap.get(sid); - if (thread == null) { - return null; - } - if (thread.isInterrupted()) { - taskThreadMap.remove(sid); - return null; - } - return thread; - } - - public void restartTask(Runnable runnable) { - stopTask(this.sid); - Thread thread = new Thread(runnable); - thread.start(); - taskThreadMap.put(this.sid, thread); - } - - public void stopTask(String sid) { - Thread thread = getTaskThread(this.sid); - if (thread != null) { - thread.stop(); - } - } } diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/websocket/context/CsWsServer.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/websocket/context/CsWsServer.java index 646647a1..7a8ca662 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/websocket/context/CsWsServer.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/websocket/context/CsWsServer.java @@ -25,16 +25,13 @@ import javax.websocket.*; import javax.websocket.server.PathParam; import javax.websocket.server.ServerEndpoint; import java.io.IOException; -import java.util.Map; import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; @Slf4j @Component @ServerEndpoint("/websocket/{sid}") @Getter public class CsWsServer { - private static final Map taskThreadMap = new ConcurrentHashMap<>(); /** * 与某个客户端的连接会话, 需要通过它来给客户端发送数据 */ @@ -138,7 +135,7 @@ public class CsWsServer { if (o == null || getClass() != o.getClass()) { return false; } - CsWsServer that = (CsWsServer) o; + CsWsServer that = (CsWsServer)o; return Objects.equals(session, that.session) && Objects.equals(sid, that.sid); } @@ -146,30 +143,4 @@ public class CsWsServer { public int hashCode() { return Objects.hash(session, sid); } - - public Thread getTaskThread(String sid) { - Thread thread = taskThreadMap.get(sid); - if (thread == null) { - return null; - } - if (thread.isInterrupted()) { - taskThreadMap.remove(sid); - return null; - } - return thread; - } - - public void restartTask(Runnable runnable) { - stopTask(this.sid); - Thread thread = new Thread(runnable); - thread.start(); - taskThreadMap.put(this.sid, thread); - } - - public void stopTask(String sid) { - Thread thread = getTaskThread(this.sid); - if (thread != null) { - thread.stop(); - } - } }