//单例模式之懒汉式
public class Singleton {
private Singleton() {
// TODO Auto-generated constructor stub
}
private static Singleton instance;
public static synchronized Singleton getInstance() {
if (instance==null) {
instance = new Singleton();
}
return instance;
}
}
本文介绍了一种实现单例模式的方法——懒汉式。通过在实例化时进行同步控制,确保了整个应用程序中只有一个实例存在。这种方法适用于资源消耗较大且希望延迟加载的情况。
5424

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



