Concurrent hash map that wraps keys and/or values in soft or weak
references. Does not support null keys or values. Uses identity equality
for weak and soft keys.
The concurrent semantics of
ConcurrentHashMap combined with the
fact that the garbage collector can asynchronously reclaim and clean up
after keys and values at any time can lead to some racy semantics. For
example,
ReferenceMap.size() returns an upper bound on the size, i.e. the actual
size may be smaller in cases where the key or value has been reclaimed but
the map entry has not been cleaned up yet.
Another example: If
ReferenceMap.get(Object) cannot find an existing entry
for a key, it will try to create one. This operation is not atomic. One
thread could
ReferenceMap.put(Object,Object) a value between the time another
thread running
get() checks for an entry and decides to create one.
In this case, the newly created value will replace the put value in the
map. Also, two threads running
get() concurrently can potentially
create duplicate values for a given key.
In other words, this class is great for caching but not atomicity.
author: crazybob@google.com (Bob Lee)
Inner Class :interface InternalReference
Inner Class :static class ReferenceAwareWrapper
Inner Class :static class KeyReferenceAwareWrapper extends ReferenceAwareWrapper
Inner Class :class SoftKeyReference extends FinalizableSoftReference
Inner Class :class WeakKeyReference extends FinalizableWeakReference
Inner Class :class SoftValueReference extends FinalizableSoftReference
Inner Class :class WeakValueReference extends FinalizableWeakReference
Inner Class :protected interface Strategy
Inner Class :protected enum PutStrategy implements Strategy
Inner Class :class Entry implements Map.Entry<K, V>
Concurrent hash map that wraps keys and/or values based on specified
reference types.
Parameters: keyReferenceType - key reference type Parameters: valueReferenceType - value reference type
Tests weak and soft references for identity equality. Compares references
to other references and wrappers. If o is a reference, this returns true
if r == o or if r and o reference the same non null object. If o is a
wrapper, this returns true if r's referent is identical to the wrapped
object.