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-02-21 19:06:10 发布
本文介绍了一种使用静态内部类及双重检查锁定实现线程安全单例模式的方法。该方法通过延迟加载实例,既保证了线程安全性又避免了同步带来的性能损失。
1901

被折叠的 条评论
为什么被折叠?



