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

          Reading notes -- Singleton pattern

          Posted on 2006-07-09 12:42 Jedi 閱讀(303) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): 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

          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 锡林浩特市| 都昌县| 文成县| 吴旗县| 石渠县| 乾安县| 曲松县| 察哈| 景泰县| 霍邱县| 云安县| 安宁市| 两当县| 阳高县| 白山市| 长岛县| 金湖县| 柳江县| 大冶市| 南澳县| 合江县| 永胜县| 田林县| 紫金县| 新郑市| 阿城市| 邮箱| 靖远县| 龙南县| 紫云| 安乡县| 沽源县| 三亚市| 巴彦淖尔市| 夏河县| 鄂州市| 图木舒克市| 南乐县| 大兴区| 读书| 崇义县|