In Singleton Design Pattern, synchronization is essential ?

 Posted by Akiii on 1/10/2012 | Category: Design Pattern & Practices Interview questions | Views: 3227 | Points: 40
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 

Comments or Responses

Posted by: SheoNarayan on: 1/11/2012 | Points: 10
Very good effort, keep this series on !

Thanks
Posted by: Akiii on: 1/12/2012 | Points: 10
Thank you very much Sheo Sir. I hope i can do better.

Regards
Akiii
Posted by: babubabu43210-22824 on: 6/29/2013 | Points: 10
This youtube link has lot of J2EE/Design pattern Related viedos and playlist has been created for easy learning
..watch and learn .. Subscribe this channal to get update about the upcoming viedos..

https://www.youtube.com/user/ramram43210/videos
https://www.youtube.com/user/ramram43210/videos?sort=da&view=0&flow=grid

Login to post response