@Component
@ServerEndpoint(value = "/endpoint/ws")
public class WebSocketServer {
private final Logger logger = LoggerFactory.getLogger(getClass());
private static final AtomicInteger onlineCount = new AtomicInteger();
@OnOpen
public void onOpen(Session session, @PathParam("sid") String sid) {
//在线数加1
onlineCount.incrementAndGet();
logger.info("新窗口监听 {}, 当前在线人数 {}",sid,onlineCount.get());
} @OnClose
public void onClose() {
//在线数减1
onlineCount.decrementAndGet();
logger.info("连接关闭, 当前在线人数为 {}",onlineCount.get());
} @OnError
public void onError(Session session, Throwable error) {
logger.warn("发生错误, 非正常关闭 {}, 当前在线人数为 {}", onlineCount.get());
}
}

最新文章

  1. Linux连接Internet
  2. web项目中,视图层中关于相对路径和绝对路径
  3. JS魔法堂:jsDeferred源码剖析
  4. Spring学习之第一个AOP程序
  5. 一些常用的vim设置
  6. Java实现批量下载《神秘的程序员》漫画
  7. JavaScript当离开页面时可以进行的操作
  8. 【杂记】SQL篇
  9. Codeforces 713D Animals and Puzzle
  10. SPOJ 274 Johnny and the Watermelon Plantation(TLE)
  11. Spark 读写hive 表
  12. hdu1698 线段树区间更新
  13. double free or corruption错误
  14. haxe相关的计划安排
  15. [Oralce][InMemory]如何确定一个表已经被Populate 到In Memory 中?
  16. A - Longest k-Good Segment (尺取法)
  17. Mysql截取和拆分字符串函数用法
  18. 7.xamarin.android 发布签名与控制apk大小
  19. Windows Azure 初体验
  20. Bootstrap学习笔记(9)--模态框(登录/注册弹框)

热门文章

  1. (二)limit的高级用法
  2. [LeetCode] 265. Paint House II 粉刷房子
  3. centos 安装 swoole_framework 框架
  4. npm创建angular项目
  5. QT QML 在qml中自定义信号
  6. (五)linux 学习 --重定向
  7. Dubbo学习摘录(一)
  8. Unity的学习笔记(UGUI文本逐个字输出)
  9. pytorch 0.4.0迁移指南
  10. serviceBehaviors_dataContractSerializer_maxItemsInObjectGraph 关键**Behavior