fix: ASW-148 使用虚拟线程检查 session 超时
This commit is contained in:
@@ -23,9 +23,6 @@ import java.net.http.HttpClient;
|
||||
import java.net.http.WebSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class EnvironmentNovncWebSocketHandler extends TextWebSocketHandler {
|
||||
@@ -53,15 +50,12 @@ public class EnvironmentNovncWebSocketHandler extends TextWebSocketHandler {
|
||||
|
||||
private IEnvironmentSessionService environmentSessionService;
|
||||
|
||||
private ScheduledExecutorService scheduler;
|
||||
|
||||
public EnvironmentNovncWebSocketHandler() {
|
||||
}
|
||||
public EnvironmentNovncWebSocketHandler(IEnvironmentService deviceService, IEnvironmentSessionService environmentSessionService, Integer sessionTimeout) {
|
||||
this.environmentService = deviceService;
|
||||
this.environmentSessionService = environmentSessionService;
|
||||
this.sessionTimeout = sessionTimeout;
|
||||
this.scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||
}
|
||||
|
||||
private void initFieldVal(WebSocketSession session) {
|
||||
@@ -195,10 +189,6 @@ public class EnvironmentNovncWebSocketHandler extends TextWebSocketHandler {
|
||||
envWebsocket.sendClose(WebSocket.NORMAL_CLOSURE, "Normal closure");
|
||||
}
|
||||
Constants.ENV_NOVNC_WEBSOCKET_SESSION.remove(sessionId);
|
||||
if (scheduler != null && !scheduler.isShutdown()) {
|
||||
scheduler.shutdownNow(); // 停止调度器
|
||||
scheduler.close();
|
||||
}
|
||||
super.afterConnectionClosed(session, status);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user