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 {@link ConcurrentHashMap} combined with thefact 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, {@link #size()} returns an upper bound on the size, i.e. the actualsize 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 {@link #get(Object)} cannot find an existing entryfor a key, it will try to create one. This operation is not atomic. One thread could {@link #put(Object,Object)} a value between the time anotherthread running {@code 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 {@code get()} concurrently can potentiallycreate duplicate values for a given key.
In other words, this class is great for caching but not atomicity.
@author crazybob@google.com (Bob Lee)