Singleton 发表于 2017-03-27 Java单例模式 1234567891011121314151617//延迟实例化(多线程)public class Singleton { private volatile static Singleton uniqueInstance; private Singleton() {} private static Singleton getInstance() { if (uniqueInstance == null) { synchronized (Singleton.class) { if (uniqueInstance == null) { uniqueInstance = new Singleton(); } } } return uniqueInstance; }} 12345678910//急切模式public class Singleton { private static Singleton uniqueInstance = new Singleton(); private Singleton() {} private static Singleton getInstance() { return uniqueInstance; }}