public V get(K k) { Vv=this.eden.get(k); if (v == null) { synchronized (longterm) { v = this.longterm.get(k); } if (v != null) { this.eden.put(k, v); } } return v; }
/** * Expunges stale entries from the table. * 遍历引用队列中的弱引用,并清除对应的Entry */ privatevoidexpungeStaleEntries() { for (Object x; (x = queue.poll()) != null; ) { synchronized (queue) { @SuppressWarnings("unchecked") Entry<K,V> e = (Entry<K,V>) x; inti= indexFor(e.hash, table.length);
Entry<K,V> prev = table[i]; Entry<K,V> p = prev; while (p != null) { Entry<K,V> next = p.next; if (p == e) { if (prev == e) table[i] = next; else prev.next = next; // Must not null out e.next; // stale entries may be in use by a HashIterator e.value = null; // Help GC size--; break; } prev = p; p = next; } } } }
强引用(StrongReference)
被强引用指向的对象,绝对不会被垃圾收集器回收。Integer prime = 1;,这个语句中 prime 对象就有一个强引用。