We have got a stateless session bean which inturn calls a method in singleton class. The method in the singleton class loads a hashtable with data which is read from xml file and returns the hastable. When concurrent users are accessing the system some of the entries in the hashtable are lost.
The method in the singleton class is not synchronised.
We are using JBoss Applicaiton server.
-
EJB Stateless Session and Singleton class (2 messages)
- Posted by: Chitra Suresh
- Posted on: August 22 2003 08:23 EDT
Threaded Messages (2)
- EJB Stateless Session and Singleton class by Ian Mitchell on August 22 2003 11:16 EDT
- EJB Stateless Session and Singleton class by Kapil Israni on August 25 2003 17:30 EDT
-
EJB Stateless Session and Singleton class[ Go to top ]
- Posted by: Ian Mitchell
- Posted on: August 22 2003 11:16 EDT
- in response to Chitra Suresh
Is your singleton a dependent object of the SLSB? If so it is not guaranteed to be a singleton because the container can instantiate SLSB's at its own discretion, and often does so for performance reasons.
Look at some of the other threads that have recently appeared on the discussion forum and the patterns forum on RMI singletons - this approach may solve your problem, but you would have to synchronise the singleton. -
EJB Stateless Session and Singleton class[ Go to top ]
- Posted by: Kapil Israni
- Posted on: August 25 2003 17:30 EDT
- in response to Chitra Suresh
I think you might wanna check the way you create(instantiate) your singleton object(single instance). i guess thats why mentioned, "synchronized". u may not be synchronizing ur crate method for the singleton.
also u might wanna pick the best pattern for ur singleton. some of them are as follows :
- a factory create method which is synchronized
- a factory create method which is "not" synchronized, but uses a "double-idiom" lock check to ensure a single instance creation
- instantiating the single instance(ur static variable) right where its defined/declared, instead of using a factory create method
I always trust the third option, the integrity of static instantiation and staic blocks is ensured n promised by the JVM.