解决WebSocket session并发问题

yun-zuoyi
汪云昊 6 years ago
parent e1a224f1a1
commit bc4147fd96

@ -82,12 +82,14 @@ public class MessageWebSocket {
public static void sendMessage(Long userId, String message){ public static void sendMessage(Long userId, String message){
try { try {
MessageWebSocket websocket = webSocketSet.get(userId); MessageWebSocket websocket = webSocketSet.get(userId);
if(websocket != null) { synchronized (websocket){
if (message.equals("heartBit")) { if(websocket != null) {
websocket.session.getBasicRemote().sendText(message + "=" + sendCount); if (message.equals("heartBit")) {
sendCount++; websocket.session.getBasicRemote().sendText(message + "=" + sendCount);
} else { sendCount++;
websocket.session.getBasicRemote().sendText(message); } else {
websocket.session.getBasicRemote().sendText(message);
}
} }
} }
} catch (IOException e) { } catch (IOException e) {

Loading…
Cancel
Save