无加锁创建单例
1 public class StaticSingleton { 2 private StaticSingleton(){ 3 System.out.println("StaticSingleton is created"); 4 } 5 private static class SingletonHolder{ 6 private static StaticSingleton instance=new StaticSingleton(); 7 } 8 public static StaticSingleton getInstance(){ 9 return SingletonHolder.instance; 10 } 11 }