Hi all,
I am using a singleton object to read configuration values from an XML file on the web server. All the class does is read values from the file, store them in instance variables, and return them via getter methods. This data is shared across the web application, and will probably never change while the application is running. Do I need to worry about
thread safety?
I thought it would make sense to make the config object a singleton, so I gave it a private constructor and a getInstance() method. As per the singleton design
pattern, I made the getInstance() method synchronized to prevent multiple instances from being created. It seems to me that it wouldn't be a problem if there were multiple instances, since they would be storing the same values, but I can't help wondering if there might be some hidden pitfall, since multi-threading with
servlets is a complex issue.
So, my question is, do I need to synchronize the methods of my config object, or can I allow multiple instances? Any help is greatly appreciated.
Here is the code. Note that the initialize() method must be called at least once before getInstance().