Posts

Showing posts with the label instance

Serializable Singleton Class

Previously I have posted about Singleton Design Pattern implementation and handling concurrency . In this post I am going to explains challenges for serializable Singleton class. Lets know about Singleton Class ( Single Design Pattern), A Singleton class restricts access to its constructor to ensure that only a single instance is ever created. I have taken example from previous post only   1: /** 2: * Singleton Class 3: * 4: * @author ydevatra 5: * 6: */ 7: public class SingletonResource implements Serializable { 8:   9: /* Private instance reference */ 10: private static SingletonResource resource = new SingletonResource(); 11:   12: /** 13: * Private constructor to restrict creation of instance of this class by 14: * other class. 15: */ 16: private SingletonResource() { 17: // Initialization code... 18: } 19:   20: ...