在实现低级Websocket服务器(无脚踩)并扩展AbstractWebSocketHandler
时,我注意到无法为相同的连接/会话同时调用handleTextMessage()
方法。
给出以下内容:
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
log(String.format("Session: %s, Thread: %s", session, Thread.currentThread()));
// simulated longrunning task
Thread.sleep(10000L);
}
调用从客户端到此处理程序的彼此快速发送3条消息时,将在10秒的间隔内生成日志输出:
Session: StandardWebSocketSession[id=0, uri=/name], Thread: Thread[http-nio-127.0.0.1-8080-exec-2,5,main], Time: 18:09:25.143
Session: StandardWebSocketSession[id=0, uri=/name], Thread: Thread[http-nio-127.0.0.1-8080-exec-2,5,main], Time: 18:09:35.152
Session: StandardWebSocketSession[id=0, uri=/name], Thread: Thread[http-nio-127.0.0.1-8080-exec-2,5,main], Time: 18:09:45.156
是否有可能配置spring来允许并发调用handleTextMessage()
处理程序?