posts - 7, comments - 1, trackbacks - 0, articles - 0

          Reading notes -- Singleton pattern

          Posted on 2006-07-09 12:42 Jedi 閱讀(303) 評論(0)  編輯  收藏 所屬分類: Design Patterns
          public ? class ?Singleton?{

          ????
          private ? volatile ? static ?Singleton?uniqueInstance;
          ????
          private ?Singleton(){
          ????????
          ????}
          ????
          ????
          public ? static ?Singleton?getInstance(){
          ????????
          if (uniqueInstance == null ){
          ????????????
          synchronized (Singleton. class ){
          ????????????????
          if (uniqueInstance == null ){
          ????????????????????uniqueInstance?
          = ? new ?Singleton();
          ????????????????}
          ????????????}
          ????????}????????
          ????????
          return ?uniqueInstance;?
          ????}

          }

          1. private constructor
          2. static getInstance
          3. syncronized..waste a lot of time
          4. double check..modified syncronize, so time-waste might occurs only when first time the instance construct

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 永昌县| 晴隆县| 沁水县| 桃江县| 名山县| 吉木萨尔县| 且末县| 五河县| 金堂县| 淳化县| 石屏县| 金昌市| 泾阳县| 南部县| 蓝山县| 繁昌县| 潞城市| 宝鸡市| 阳山县| 涡阳县| 镇巴县| 绥宁县| 沭阳县| 墨脱县| 龙陵县| 杭锦后旗| 陆良县| 肇州县| 白朗县| 杨浦区| 雷州市| 龙胜| 安丘市| 通渭县| 突泉县| 邵东县| 广州市| 佛坪县| 奉节县| 万安县| 东平县|