//線程安全且加了同步鎖安全
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/51682927ide