I was going through design pattern and came across with Singleton Pattern
class SingletonPattern implements Runnable {
private static SingletonPattern single=null;
private SingletonPattern() { }
public synchronized static SingletonPattern getInstance() {
if(null==single) {
single=new SingletonPattern();
}
return single;
}
}
Now I understand that synchronized will help that two thread cannot access the getInstance method but correct me if I am wrong two different object will have two locks each having one.Another thread can be started from anther object and get then access the getInstance() method thus we can have two objects.??