标签:单例设计 nal zed new stat 单例模式 class ret let
class Singleton {
/**
* 单例模式---饿汉式
*/
private static final Singleton s = new Singleton();
private Singleton() {
}
public static Singleton getInstance() {
return s;
}
}
class SingletonLazy {
/**
* 单例模式---懒汉式
*/
private static SingletonLazy s;
private SingletonLazy() {
}
/**
* 解决并发线程不安全问题
*/
public synchronized static SingletonLazy getInstance() {
if (null == s)
s = new SingletonLazy();
return s;
}
}
标签:单例设计 nal zed new stat 单例模式 class ret let
原文地址:https://www.cnblogs.com/blogfyang/p/12160611.html