//[代码2]声明一个公有的静态的成员丽数getInstance,方法判断instance//成员变量是否为空,如果为空,则根据构造函数新建一个对象,否则返回instance
public class DoubleLock {
private volatile static DoubleLock instance;
private DoubleLock(){}
public static DoubleLock getInstance() {
if (instance == null) {
synchronized(DoubleLock.class){
if (instance == null) {
instance = new DoubleLock();
}
}
}
return instance;
}
}