Question: Consider the following code on Singleton to answer below questions: public class Driver { private static Driver instance; private Driver ( ) { } public

Consider the following code on Singleton to answer below questions:
public class Driver {
private static Driver instance;
private Driver(){}
public static synchronized Driver getInstance(){
if(instance == null){ instance = new Driver(); }
return instance;
}
}
Which OO basics is used by the Singleton pattern, justify your answer?
Can we consider the instance of Driver in the above code thread-safe? Explain your answer?
What is the issue with this code?
rewrite the above code to make it better based on your answer in 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!