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

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

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

    posts - 72, comments - 66, trackbacks - 0, articles - 0

    2010年3月2日


    sudo vim /etc/vmware/config

    在最下面添加一句話:
    xkeymap.nokeycodeMap = true

    posted @ 2010-06-09 15:39 Fingki.li 閱讀(590) | 評論 (0)編輯 收藏

    在使用Iterator處理Collection時,注意java.util.ConcurrentModificationException。
    1.如果你僅僅是對collection進行遍歷查詢,那么不必擔心什么。
    2.但如果你在遍歷過程中要對collection進行刪除,那么你就要注意了。
    For example:
    private void testDel() {  
    1.     List<String> list = new ArrayList<String>();  
    2.     for (int i = 0; i < 10; i++) {  
    3.         String str = "td" + i;  
    4.         list.add(str);  
    5.     }  
    6.   
    7.     for (Iterator it = list.iterator(); it.hasNext();) {  
    8.         String str = (String) it.next();  
    9.         if (str.equals("td5")) {  
    10.             // list.remove(str);  // 刪除方法一 
    11.             it.remove();  // 刪除方法二 
    12.         }  
    13.     }  

    上面的代碼運行沒有問題,但如果你用“方法一”替代“方法二”,則會出現(xiàn)java.util.ConcurrentModificationException。
    (用for-each遍歷也會出個類似問題)
    具體原因是可以看一下先看看List中的remove方法源碼:
    1. public boolean remove(Object o) {  
    2.     if (o == null) {  
    3.         for (int index = 0; index < size; index++)  
    4.             if (elementData[index] == null) {  
    5.                 fastRemove(index);  
    6.                 return true;  
    7.             }  
    8.     } else {  
    9.         for (int index = 0; index < size; index++)  
    10.             if (o.equals(elementData[index])) {  
    11.                 fastRemove(index);  
    12.                 return true;  
    13.             }  
    14.     }  
    15.     return false;  
    16. }  
    17.   
    18. private void fastRemove(int index) {  
    19.     modCount++; // 特別注意這里,這里只增加了modCount的值  
    20.     int numMoved = size - index - 1;  
    21.     if (numMoved > 0)  
    22.         System.arraycopy(elementData, index + 1, elementData, index,  
    23.                 numMoved);  
    24.     elementData[--size] = null; // Let gc do its work  

    接著看。刪除后得到下一個元素的代碼,it.next():  it為AbstractList的內(nèi)部類Iterator的一個實例。
    1. public E next() {  
    2.     checkForComodification();  
    3.     try {  
    4.         E next = get(cursor);  
    5.         lastRet = cursor++;  
    6.         return next;  
    7.     } catch (IndexOutOfBoundsException e) {  
    8.         checkForComodification();  
    9.         throw new NoSuchElementException();  
    10.     }  
    11. }  
    12.   
    13. final void checkForComodification() {  //注意這個方法
    14.     if (modCount != expectedModCount)  //檢查這兩個值是否相同
    15.         throw new ConcurrentModificationException();  

    最后看Iterator的remove()方法的源代碼:
    1. public void remove() {  
    2.     if (lastRet == -1)  
    3.         throw new IllegalStateException();  
    4.     checkForComodification();  
    5.     try {  
    6.         AbstractList.this.remove(lastRet);  
    7.         if (lastRet < cursor)  
    8.             cursor--;  
    9.         lastRet = -1;  
    10.         expectedModCount = modCount; // 設(shè)置expectedModCount  
    11.     } catch (IndexOutOfBoundsException e) {  
    12.         throw new ConcurrentModificationException();  
    13.     }  
    14. }  
    15.   
    16. final void checkForComodification() {  
    17.     if (modCount != expectedModCount)  
    18.         throw new ConcurrentModificationException();  

    這下就明白了,list的remove方法只修改了modCount值,而iterator的remove能同步modCount和expectedModCount.



    posted @ 2010-03-02 12:22 Fingki.li 閱讀(5084) | 評論 (1)編輯 收藏

    Ubuntu 時區(qū)時間設(shè)置:
    執(zhí)行
    tzselect(有的版本用tzconfig)
    按照提示進行選擇時區(qū)
    sudo cp /usr/share/zoneinfo/Asia/ShangHai /etc/localtime
    執(zhí)行
    sudo ntpdate cn.pool.ntp.org
    cn.pool.ntp.org是位于中國的公共NTP服務(wù)器,用來同步你的時間

    時間
    sudo date

    posted @ 2010-03-02 11:51 Fingki.li 閱讀(466) | 評論 (0)編輯 收藏

    主站蜘蛛池模板: 女人被男人桶得好爽免费视频| 永久在线观看免费视频 | 国产在线观看免费视频播放器| 综合自拍亚洲综合图不卡区| 久久青草免费91线频观看不卡 | 亚洲A∨精品一区二区三区下载| 青青青免费国产在线视频小草| 亚洲国产精品午夜电影| 无码国产精品一区二区免费虚拟VR | 亚洲不卡1卡2卡三卡2021麻豆| 波多野结衣中文字幕免费视频 | 亚洲色欲www综合网| 国产精品久久永久免费| 亚洲人成在线中文字幕| 成人毛片18岁女人毛片免费看| 亚洲精品无码mⅴ在线观看| 四虎影视精品永久免费| 国产免费人成视频尤勿视频| 国产亚洲人成网站在线观看不卡| 久久午夜免费鲁丝片| 亚洲一欧洲中文字幕在线| 国产高清免费在线| 高清免费久久午夜精品| 亚洲va无码va在线va天堂| 在线成人爽a毛片免费软件| 亚洲一级特黄特黄的大片 | 永久免费bbbbbb视频| 全部一级一级毛片免费看| 亚洲VA中文字幕无码一二三区| 91精品视频在线免费观看| 亚洲色欲啪啪久久WWW综合网| 日韩亚洲国产综合久久久| 久久国产乱子伦精品免费一| 国产成人精品日本亚洲直接| 久99精品视频在线观看婷亚洲片国产一区一级在线 | 日本在线免费观看| 亚洲综合av一区二区三区不卡| 亚洲AV无码一区二区三区在线观看| 大地影院MV在线观看视频免费| 激情综合亚洲色婷婷五月APP| 亚洲国产精品尤物YW在线观看|