java - How to maintain state with GlassFish4 Socket Server? -


i building game using socket server via glassfish 4.

the problem i'm running that,

every time socket connection made @serverendpoint class re-instantiated.

i'm looking class kicks off glassfish 4 server similar writing servlet in tomcat. need place initialize state of game, thought server end-point place, it's re-initializing game state every time open connection (which problematic).

i write game state containers singletons or static classes static initializers, like avoid both of things , instantiate all of game state containers in, guess the class sits listening web socket connections?

i haven't been able find in glassfish tutorials have read through.

i have found solution this. not declaring data structures "static final". doing "private hashmap<> x;" resulted in "x" being reinstantiated every time new connection opened.

"private static final hashmap<> x;" looks stopped doing this.


Comments