concurrentHashMap源碼(JDK1.6)get方法中為什么要readValueUnderLock(e),v為null究竟是怎么產(chǎn)生的?put方法中有這么一段:tab[index] = new HashEntry<K,V>(key, hash, first, value);難道在執(zhí)行構(gòu)造方法中會(huì)存在中間狀態(tài)?value還沒有賦值就能讀到?V get(Object key, int hash) { if (count != 0) { // read-volatile HashEntry<K,V> e = getFirst(hash); while (e != null) { if (e.hash == hash && key.equals(e.key)) { V v = e.value; if (v != null) return v; return readValueUnderLock(e); // recheck } e = e.next; } } return null;}V readValueUnderLock(HashEntry<K,V> e) { lock(); try { return e.value; } finally { unlock(); } }
concurrentHashMap源碼中的readValueUnderLock(e)存在的意義?
慕尼黑8549860
2019-03-29 23:19:53