单例模式【SINGLETON PATTERN】
程序员文章站
2022-07-14 07:59:24
...
public class Singleton
{
// private static Singleton singleton = null;
//
// private Singleton()
// {
// }
//
// public static Singleton getInstance()
// {
// if (singleton == null)
// {
// singleton = new Singleton();
// }
// return singleton;
// }
private Singleton(){}
private static Singleton instance = null;
public static Singleton getInstance() {
if (instance == null) {
synchronized (Singleton.class) {
if (instance == null) {
instance = new Singleton();
}
}
}
return instance;
}
}
上一篇: C
下一篇: JS不使用替换进行替换