报错:
高并发情况下,使用websocket出现报错:The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method。
报错原因:
一.
使用
session.getAsyncRemote().sendText(message); //异步发送
异步调用,但没有加锁,导致一个Session正在使用中,又被另一个线程调用。
二.
修改为:
synchronized(session){
session.getAsyncRemote().sendText(message);
}
依然报错。
三.
改为同步调用:
synchronized(session){
session.getBasicRemote().sendText(message);
}
上述问题解决,但并发量较大情况下,有可能出现响应超时。