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

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


          網站導航:
           
          主站蜘蛛池模板: 太白县| 织金县| 积石山| 兴安县| 达拉特旗| 鄯善县| 黄冈市| 汽车| 邳州市| 西平县| 饶平县| 刚察县| 涿鹿县| 峨山| 来安县| 万安县| 石首市| 永城市| 六安市| 乾安县| 竹北市| 和静县| 和田市| 滨州市| 土默特右旗| 黔江区| 库伦旗| 江川县| 东平县| 司法| 竹溪县| 城市| 平昌县| 伊金霍洛旗| 内江市| 罗城| 法库县| 郧西县| 宜州市| 民丰县| 天祝|