ConcurrentHashMap(jdk1.7)put操作确定segment后,加锁失败时,自旋外还在遍历链表,什么目的,感觉毫无意义啊privateHashEntryscanAndLockForPut(Kkey,inthash,Vvalue){ HashEntryfirst=entryForHash(this,hash); HashEntrye=first; HashEntrynode=null; intretries=-1;//negativewhilelocatingnodewhile(!tryLock()){HashEntryf;//torecheckfirstbelow if(retries<0){if(e==null){if(node==null)//speculativelycreatenodenode=newHashEntry(hash,key,value,null); retries=0;}elseif(key.equals(e.key))retries=0;elsee=e.next;}elseif(++retries>MAX_SCAN_RETRIES){lock();break;}elseif((retries&1)==0&&(f=entryForHash(this,hash))!=first){e=first=f;//re-traverseifentrychangedretries=-1;}}returnnode;}改成这样有啥问题呢:privateHashEntryscanAndLockForPut(Kkey,inthash,Vvalue){ HashEntrynode=newHashEntry (hash,key,value,null); intretries=-1;//negativewhilelocatingnodewhile(!tryLock()){if(++retries>MAX_SCAN_RETRIES){lock();break;}}returnnode;}
精慕HU
呼啦一阵风
相关分类