When to use Singleton: Singleton is used there must be one instance of the class. And it must be accessable to clients from global point.
Example usage of Singleton: Logger object, Configuration object, Cache object, Properties Object, Factory methods are used Single ton, etc..
Problems of singleton:
1) Multi-thread safe. ( method level it self)
2) Lazy installation using double locking machanism, (Synchronized inside the getInstalnce() method)
3) Early installtion method.
4) Serialization. (serializable(), readResolve())
Example usage of Singleton: Logger object, Configuration object, Cache object, Properties Object, Factory methods are used Single ton, etc..
Problems of singleton:
1) Multi-thread safe. ( method level it self)
2) Lazy installation using double locking machanism, (Synchronized inside the getInstalnce() method)
3) Early installtion method.
4) Serialization. (serializable(), readResolve())
No comments:
Post a Comment