In Singleton Design Pattern
, synchronization is essential only for the first time when the instance is to be created. When the instance is created then it becomes an overhead for each request.
public class Singleton
private static Singleton uniqueinstance;
public static Singleton getinstance()
if(uniqueinstance == null)
uniqueinstance = new Singleton();
In the above code, when for the first time getinstance method is called, synchronization is needed. After the first instance is created, we no longer need synchronization.
Thanks and Regards
Asked In: Some Interviews |