Friday, May 13, 2011

In Java when is a singleton not exactly a singleton ?

A wonderful article on Sun/Oracle site, talking about the various situations when a Singleton in Java is actually not a Singleton.


Would highly recommend going through the above article, but the one which actually struck me was that within a given Java VM different classloaders can actually instantiate singletons more than once. E.g. two applications running within a WebSphere Application Server on a Single Java Virtual Machine would instantiate the Singleton (if being used in both the applications) twice as both the applications use their own classloaders wherein the classes loaded by one classloader does not have visibility on the classes loaded by the other classloader.

1 comment: