How can you make sure that your singleton class will always return single instance in multi-threaded environment?



How can you make sure that your singleton class will always return single instance in multi-threaded..

Answer / Rajdeep Gupta

To ensure a singleton class returns the same instance across all threads, you can use double-checked locking or enum mechanism. Another approach is using the Hungarian Hunger pattern. The key idea is to make the constructor private and provide a static method to access the single instance.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

Is oracle charging for java?

1 Answers  


In multi-threading how can we ensure that a resource isn't used by multiple threads simultaneously?

1 Answers  


What is math floor in java?

1 Answers  


Are maps ordered java?

1 Answers  


what is difference between set and list in collection?

3 Answers   Satyam,


take an array with -ve and +ve value both.find out the nearest value of 0(zero).if two values are same like(-2 and +2)then extract +2 is nearest of 0(zero).

1 Answers  


What is double checked locking in singleton?

1 Answers  


waht happens when a return type ,even void is specified for a constructor?

11 Answers  


Can u overload main()method.Give with example.

6 Answers   IBM, Schimatic Technologies,


What is parameter tag and what is its use?

1 Answers  


What is linkedlist in java?

1 Answers  


What is broken and continue statement?

1 Answers  


Categories