Possible Duplicate:
cracking singleton with other ways
Can anyone please tell me when a Singleton
would not work as a Singleton
?
Possible Duplicate:
cracking singleton with other ways
Can anyone please tell me when a Singleton
would not work as a Singleton
?
There is very good post published on Sun website by author Joshua Fox. Please go through this.
below are some of them scenario when your Singleton
doesn't behave like.
A singleton (in Java land) wouldn't work as a singleton if a given class is loaded by multiple class-loaders. Since a single class can exist (or can be loaded) in multiple classloaders, it's quite possible to have "multiple" instances of a "supposedly" singleton class for a given JVM instance. But this is a pretty rare case and doesn't happen a lot. :)
If you are able to create more than one instance of the class then it doesn't remain singleton by using ways like cloning, De-serialization etc.