隨筆-84  評論-56  文章-0  trackbacks-0
          public class Singleton {
          private final static Singleton instance = new Singleton();
          // Private constructor suppresses generation of a (public) default constructor
          private Singleton() {}
          public static Singleton getInstance() {
          return instance;
          }
          }
          public class Singleton {
          private static Singleton instance;
          // Private constructor suppresses generation of a (public) default constructor
          private Singleton() {}
          public static synchronized Singleton getInstance() {
          if(instance == null) {
          instance = new Singleton();
          }
          return instance;
          }
          }
          public class Singleton {
          // Private constructor suppresses generation of a (public) default constructor
          private Singleton() {}
          private static class SingletonHolder {
          private static Singleton instance = new Singleton();
          }
          public static Singleton getInstance() {
          return SingletonHolder.instance;
          }
          }
          public class Singleton {
          private volatile static Singleton instance;
          // Private constructor suppresses generation of a (public) default constructor
          private Singleton() {}
          public static Singleton getInstance() {
          if(instance == null) {
          synchronized(Singleton.class) {
          if(instance == null) {
          instance = new Singleton();
          }
          }
          }
          return instance;
          }
          }
          posted on 2008-08-24 05:21 憶風 閱讀(235) 評論(0)  編輯  收藏 所屬分類: 設計模式

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 平武县| 安顺市| 满城县| 兴海县| 富裕县| 江口县| 萨迦县| 广安市| 旺苍县| 乐昌市| 宝丰县| 宁乡县| 郸城县| 南昌县| 凤阳县| 天台县| 锦州市| 澄江县| 芜湖县| 大港区| 临湘市| 怀柔区| 兴业县| 甘孜| 浏阳市| 昌图县| 湖南省| 阿城市| 井冈山市| 堆龙德庆县| 枝江市| 土默特左旗| 威信县| 乌鲁木齐县| 南平市| 乐平市| 阳江市| 桂平市| 莱州市| 宁海县| 锡林郭勒盟|