标签:style blog color div sp log on c new
1.懒汉式(内部类式)
/**
* Created by pmx on 14-9-14.
*/
public class Singleton {
private Singleton() {}
public static Singleton getInstance() {
return SingletonHolder.instance;
}
static class SingletonHolder {
private static Singleton instance = new Singleton();
}
}
2.懒汉式(同步)
/** * Created by pmx on 14-9-14. */ public class Singleton { private static Singleton singleton = null; private Singleton() {} public static Singleton getInstance() { if (singleton == null) { synchronized (Singleton.class) { if (singleton == null) singleton = new Singleton(); } } return singleton; } }
标签:style blog color div sp log on c new
原文地址:http://www.cnblogs.com/tiny1990/p/3971550.html