隨筆-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 憶風 閱讀(239) 評論(0)  編輯  收藏 所屬分類: 設計模式

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 江门市| 丽水市| 富源县| 仙桃市| 苏州市| 姚安县| 卢氏县| 泸西县| 怀宁县| 新乡县| 巨鹿县| 法库县| 南安市| 十堰市| 双流县| 南澳县| 崇州市| 蒙山县| 桑植县| 建德市| 忻州市| 兴城市| 林西县| 嘉峪关市| 永清县| 古交市| 崇左市| 平潭县| 府谷县| 永城市| 巴彦县| 剑阁县| 汤原县| 买车| 井冈山市| 噶尔县| 孟州市| 海淀区| 营口市| 建阳市| 砀山县|