//线程安全且加了同步锁
public class Singleton { private volatile static Singleton singleton; public Singleton() { } public static Singleton getInstance() { if (singleton == null) { synchronized (Singleton.class) { if (singleton == null) { singleton = new Singleton(); } } } return singleton; }}
来自: http://blog.csdn.net/zxw136511485/article/details/51682927