public class SingleInstance {
static volatile SingleInstance defaultInstance;
public static SingleInstance getDefault() {
if (defaultInstance == null) {
synchronized (SingleInstance.class) {
if (defaultInstance == null) {
defaultInstance = new SingleInstance();
}
}
}
return defaultInstance;
}
}
JAVA设计模式之单例模式(双重锁定)
最新推荐文章于 2024-04-19 20:11:47 发布