Java Web Socket ServerEndpoint Thread Safety

点点圈 提交于 2019-12-05 17:14:22

By default, each client connection creates new @ServerEndpoint instance. (this seems to be the answer for the last question as well).

Static objects (or access to them) MUST be synchronized.

Linked example uses synchronizedSet, so it seems to be OK.

Additionally - @OnMessage method won't be triggered before previous @OnMessage processing ends, BUT it can be invoked from different thread. Meaning you will always process incoming messages sequentially.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!