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

          Reading notes -- Singleton pattern

          Posted on 2006-07-09 12:42 Jedi 閱讀(307) 評論(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

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


          網站導航:
           
          主站蜘蛛池模板: 阿鲁科尔沁旗| 电白县| 留坝县| 南陵县| 兰坪| 外汇| 两当县| 襄垣县| 宁化县| 紫阳县| 济源市| 宜州市| 伊宁市| 蓝山县| 广河县| 丰原市| 顺平县| 汝阳县| 永定县| 阿拉善盟| 松江区| 永善县| 遂溪县| 冕宁县| 肇庆市| 盘山县| 阿克陶县| 阿图什市| 九龙坡区| 黔江区| 东辽县| 洛浦县| 辉县市| 民乐县| 雷波县| 固安县| 南雄市| 乌什县| 和顺县| 繁昌县| 罗山县|