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.
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.
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.