在Tomcat 8.5.9中,session.getAsyncRemote().sendText()方法会抛出java.lang.IllegalStateException异常,错误信息为"The remote endpoint was in state [TEXT_FULL_WRITING]"。为了解决该问题,可以在调用send方法前加入互斥锁(mutex),在调用后释放该锁。
当调用此方法时,仍会抛出异常。除了此方法外,没有调用session.getAsyncRemote().sendText()或session.getBasicRemote().sendText()。ServerEndpoint在onMessage方法中返回void。
谢谢。
sendMutex.acquireUninterruptibly();
try{
session.getAsyncRemote().sendText(gson.toJson(message));
}catch(Exception exception){
logger.error("Session : "+session.getId()+" message : "+gson.toJson(message)+" exception : "+exception.getMessage(),exception);
}
sendMutex.release();
当调用此方法时,仍会抛出异常。除了此方法外,没有调用session.getAsyncRemote().sendText()或session.getBasicRemote().sendText()。ServerEndpoint在onMessage方法中返回void。
谢谢。