当用户断开链接并重新链接时会先执行三次onclose函数再重新join(room),我重写了onclose方法,计算当前在线人数,但是断线之后就会执行三次onclose,导致没有计算,请问大神是什么原因
@Override
public void onClose(Session session, CloseReason closeReason) {
//人数-1
subOnlineCount();
System.out.println("有一链接关闭!当前在线人数为" + getOnlineCount());
//调用父类的onclose
super.onClose(session, closeReason);
}
openId_4加入房间roomId_1!当前在线总人数为2
2017-11-19 16:59:59,869 org.nutz.plugins.mvc.websocket.handler.AbstractWsHandler.join(AbstractWsHandler.java:50) DEBUG - session(id=4lpo6q02p2j9qoqqjtebatgird) join room(name=wsroom:roomId_1)
2017-11-19 16:59:59,870 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT * FROM game_user where open_id ='openId_4' LIMIT 0, 1
有一链接关闭!当前在线人数为1
2017-11-19 17:00:21,854 org.nutz.plugins.mvc.websocket.handler.AbstractWsHandler.left(AbstractWsHandler.java:59) DEBUG - session(id=4lpo6q02p2j9qoqqjtebatgird) left room(name=wsroom:roomId_1)
有一链接关闭!当前在线人数为0
有一链接关闭!当前在线人数为-1