Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Is static ConcurrentHashMap a reliable choice for WebSocketServlet?

Hi Lachlan, thank you for your comments! 

Over the weekend I have rewritten the custom WebSocketListener in my little word game to have a static ConcurrentHashMap of ConcurrentHashMaps with the outer key being user ids and with the inner keys being strings made of session.getRemoteAddress().getHostString() + ":" + session.getRemoteAddress().getPort() - because they identify the multiple Sessions for a user (when she/he uses several browser tabs or maybe uses desktop and mobile versions at the same time):

https://gist.github.com/afarber/4f82205881ddb0223130f74b4e87abda

And yes, I had also the structure in the servlet before and passed it by a custom WebSocketCreator. Both variants work and of course Jetty has only 1 process (I can see it on my Linux machine).

At the same I have followed Joakim's advice and decreased the idle timeout to 5 minutes. 

And additionally I track when there is no human actions at the remote end for 5 minutes - and close those sessions at my servlet (to handle the abandoned browser tabs). I didn't have to use ping in my code...

I have impression that Jetty source code is very stable and overall excellent, thank you

Sorry if my mail was a bit offtopic

Best regards
Alex



Back to the top