public class A{
private A() {} //私有构造函数
private volatile static Ainstance = null; //单例对象
//静态工厂方法
public static A getInstance() {
if (instance == null) { //双重检测机制
synchronized (A.class){ //同步锁
if (instance == null) { //双重检测机制
instance = new A();
}
}
}
return instance;
}
}
网友评论