1 class Singleton{ 2 // 1:私有化构造方法 3 private Singleton(){}; 4 5 // 2:私有的静态内部类,类加载器负责加锁 6 private static class SingletonHolder{ 7 private static Singleton singleton = new Singleton(); 8 } 9 10 // 3:自行对外提供实例 11 public static Singleton getInstance(){ 12 return SingletonHolder.singleton; 13 } 14 }