Hi Ingle,
First of all singletons are not the best choice with
j2ee applications. One obvious reason could be the clustered environments, where you�ll have one singleton per server instance.
Having said that, here there is my general opinion: synchronize the getInstance() method in your singleton class and that should work, like in this example (got it from the same site):
And here there are my thoughts:
The problem that the Double-Checked Locking tries to solve is the inefficiency of synchronizing the whole method. Well let me tell you what I think: there is no inefficiency here, because this method takes exactly 0ms to execute; it runs so fast that the execution time is practically un-measurable. Next question to ask is how many concurrent threads will run this piece of code "simultaneously" and how long the delay would be? As you might guess this is also limited by the number of threads that the jvm was configured to use (which could be around 70, in order for the setting to become contra-productive). As for the delay... I expect it to be un-measurable as well. You can also run several loading tests and make sure that this is not a bottleneck in your application.
Regards.