Answer: 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;
private Singleton()
{
}
public static Singleton getinstance()
{
if(uniqueinstance == null)
{
uniqueinstance = new Singleton();
}
return uniqueinstance;
}
}
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
Akiii
Asked In: Some Interviews |
Alert Moderator