Search Interview Questions
| 3356 questions in repository.|
There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Have a video suggestion.
Click Correct / Improve and please let us know.
|Java - 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 ?|
|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 ?|
|Should we have instance variables in the Spring Bean which has been scoped as Singleton ?|
|What are stateless objects ? How are they different from immutable objects ? Which of these two is thread safe ?|
|Action Class is singleton and hence not thread safe in ..|
|Which of the following is not the difference between Singleton and Static class ( Class with static members only ) ?|