public class SingletonTest {
private static SingletonTest instance = null;
private SingletonTest() {
}
private static synchronized void syncInit() {
if (instance == null) {
instance = new SingletonTest();
}
}
public static SingletonTest getInstance() {
if (instance == null) {
syncInit();
}
return instance;
}
}
多线程情况下的单例模式创建
最新推荐文章于 2025-03-20 19:34:52 发布
本文详细介绍了Java中单例模式的实现方式,并通过代码示例深入探讨了同步初始化和懒汉式两种实现方法的优缺点。
1740

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



