无加锁创建单例

 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 }

 

posted on 2019-04-01 21:21  十字街~  阅读(132)  评论(0编辑  收藏  举报