来源: http://www.cnblogs.com/coffee/archive/2011/12/05/inside-java-singleton.html
其中有一个方法
public static SingletonThree getInstance() {
if (instance == null) {
synchronized (SingletonThree.class) { // 1
SingletonThree temp = instance; // 2
if (temp == null) {
synchronized (SingletonThree.class) { // 3 这里问什么再加一个锁呢?
temp = new SingletonThree(); // 4
}
instance = temp; // 5
}
}
}
return instance;
}
请问在 //3 的位置,为什么再加一个锁呢?百思不得其解,求教