<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Dev Zone
    偏執(zhí)狂才能生存,人生/事業(yè)的路上需要再堅持一下
    但是又怎么說得清堅持的結(jié)果,道得盡堅持的含義
    Ofbiz2.1有兩個bug,都涉及到線程安全性,小并發(fā)的時候不容易發(fā)現(xiàn),大并發(fā)下有時候會出現(xiàn),并發(fā)數(shù)越高出現(xiàn)的頻度就比較高,尤其對于實體引擎的那個bug,在系統(tǒng)初始化的時候如果遭遇大并發(fā),會有一定頻度的出現(xiàn)。
     
    1。entity engine的ModelEntity.getField方法存在線程安全隱患,會造成 XXXX is not a field of XXX的異常,以下是原有代碼片斷:

        
    public ModelField getField(String fieldName) {
            
    if (fieldName == nullreturn null;
            if (fieldsMap == null) {
                fieldsMap = new HashMap(fields.size());
                for (int i = 0; i < fields.size(); i++) {
                    ModelField field = (ModelField) fields.get(i);
                    fieldsMap.put(field.name, field);
            }
            return (ModelField) fieldsMap.get(fieldName);
        }

    由于getField方法沒有同步(會造成性能下降),因此紅色標(biāo)標(biāo)注的那段代碼存在線程安全問題,必須進(jìn)行同步。在大并發(fā)下如果多個調(diào)用這個方法,最先調(diào)用的線程沒有執(zhí)行完循環(huán)的情況下,后續(xù)的線程通過最后的語句return的時候得到的就是Null(fieldsMap已經(jīng)被第一個線程賦值了,后續(xù)線程不會進(jìn)入紅色標(biāo)準(zhǔn)的代碼區(qū)域)。
    修改后的代碼如下:
       public ModelField getField(String fieldName) {
            
    if (fieldName == nullreturn null;
            
    if (fieldsMap == null) {
                 createFields();
            }
            
    return (ModelField) fieldsMap.get(fieldName);
        }

        
    public synchronized void createFields()
        {
                 fieldsMap 
    = new HashMap(fields.size());
     
                 
    for (int i = 0; i < fields.size(); i++) {
                     ModelField field 
    = (ModelField) fields.get(i);
     
                     fieldsMap.put(field.name, field);
                 }
        }
     
    這個Bug在3.0中已經(jīng)被修正。
     
    2。UtilCache.get方法同樣存在線程安全隱患,會造成LinkedList.remove或者LinedList.addFirst的空值針異常,不注意還會以為是LinkedList的bug。以下是原代碼片斷:
        public Object get(Object key) {
            
    if (key == null) {
                missCount
    ++;
                
    return null;
            }
            UtilCache.CacheLine line 
    = (UtilCache.CacheLine) cacheLineTable.get(key);
            
    if (hasExpired(line)) {
                
    // note that print.info in debug.properties cannot be checked through UtilProperties here, it would cause infinite recursion
                
    // if (Debug.infoOn()) Debug.logInfo("Element has expired with key " + key);
                remove(key);
                line 
    = null;
            }
            
    if (line == null) {
                
    // if (Debug.infoOn()) Debug.logInfo("Element not found with key " + key);
                missCount++;
                
    return null;
            }
            
    // if (Debug.infoOn()) Debug.logInfo("Element found with key " + key);
            hitCount++;
            if (maxSize > 0) {
                keyLRUList.remove(key);
                keyLRUList.addFirst(key);
            }

            return line.getValue();
        }
    紅色標(biāo)準(zhǔn)的部分是有問題的代碼,修改后的代碼如下:
        public Object get(Object key) {
            
    if (key == null) {
                missCount
    ++;
                
    return null;
            }
            UtilCache.CacheLine line 
    = (UtilCache.CacheLine) cacheLineTable.get(key);
            
    if (hasExpired(line)) {
                
    // note that print.info in debug.properties cannot be checked through UtilProperties here, it would cause infinite recursion
                
    // if (Debug.infoOn()) Debug.logInfo("Element has expired with key " + key);
                remove(key);
                line 
    = null;
            }
            
    if (line == null) {
                
    // if (Debug.infoOn()) Debug.logInfo("Element not found with key " + key);
                missCount++;
                
    return null;
            }
            
    // if (Debug.infoOn()) Debug.logInfo("Element found with key " + key);
            hitCount++;
            
    if (maxSize > 0) {
                synchronized ( 
    this)
                {
                     keyLRUList.remove(key);
                     keyLRUList.addFirst(key);
                }
            }
            
    return line.getValue();
        }

    這個BUG在3.0種也修正了。
    posted on 2005-05-17 22:07 dev 閱讀(313) 評論(0)  編輯  收藏

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


    網(wǎng)站導(dǎo)航:
     
     
    主站蜘蛛池模板: 亚洲一级片在线播放| 理论亚洲区美一区二区三区| 国产成在线观看免费视频| 亚洲中文无码永久免| 国产AV无码专区亚洲AWWW| 亚洲网站在线免费观看| 深夜免费在线视频| 久久亚洲AV无码精品色午夜麻| 中文字幕无码不卡免费视频| 本免费AV无码专区一区| 亚洲中字慕日产2021| 亚洲精品视频在线看| 青青青免费国产在线视频小草| 成年免费a级毛片| 亚洲一区二区三区91| 亚洲色成人WWW永久网站| 毛片A级毛片免费播放| 成人片黄网站色大片免费观看cn| 亚洲人成毛片线播放| 国产成人精品日本亚洲专区| 无码区日韩特区永久免费系列 | 免费va在线观看| 91福利视频免费观看| 黄页网站在线视频免费| 亚洲成AV人片久久| 亚洲人成网7777777国产| 国产在线98福利播放视频免费| 99热在线观看免费| 99精品视频免费| 色天使色婷婷在线影院亚洲| 亚洲美女视频网站| 亚洲日产韩国一二三四区| 免费国产小视频在线观看| 性做久久久久久免费观看| 午夜免费福利小电影| 国产黄片不卡免费| 黄色a级片免费看| 亚洲成AV人片高潮喷水| 亚洲www77777| 亚洲剧场午夜在线观看| 无码专区—VA亚洲V天堂|