Search Interview Questions
| More than 3000 questions in repository.|
There are more than 900 unanswered questions.
Click here and help us by providing the answer.
Have a video suggestion.
Click Correct / Improve and please let us know.
|Interview Questions and Answers|
|Ans. In First Case , Lock for the synchronized block will be received only if singleton == null whereas in second case every thread will acquire the lock before executing the code.|
The problem of synchronization with singleton will only happen when the object has not be instantiated. Once instantiated , the check singleton == null will always generate true and the same object will be returned and hence no problem. First condition will make sure that synchronized access ( acquiring locks ) will only take place if the object has not been created so far.
|Help us improve. Please let us know the company, where you were asked this question :|
|Like Discuss Correct / Improve  java   singleton   synchronization|
Try 1 Question(s) Test
|Difference between Static and Singleton Class ?|
|What is the difference between Singleton and Prototype Bean scope in Spring ?|
|serialization and deserialization of singleton class|
|How to avoid cloning, serialization in the singleton class ?|
|When singleton can break and how to resolve it|
|If you are given choice to either load object eagerly or lazily , which one would you use in case of singleton pattern ?|
|When should we use prototype scope and singleton scope for beans ?|
|Explain Singleton Design Pattern ?|
|Shouldn't we make a class with all static members is its just expected to be executed as a standalone program with just one thread. Moreover Lets assume that there is no runtime Polymorphism required and there is no need for serialization ?|