ConcurrentHashMap that uses soft or
weak references for both keys and values.
This class can be used as an alternative to
Collections.synchronizedMap(new WeakHashMap<K, Reference<V>>()) in order to
support better performance when accessed concurrently. This implementation follows the
same design constraints as ConcurrentHashMap with the exception that
null values and null keys are supported.
Note
The use of references means that there is no guarantee that items placed into the map will be subsequently available. The garbage collector may discard references at any time, so it may appear that an unknown thread is silently removing entries.
If not explicitly specified, this implementation will use soft entry references.
| Modifier and Type | Class and Description |
|---|---|
| private static interface | ConcurrentReferenceHashMap.Entries<V>
Allows a task access to |
| protected static class | |
| private class | ConcurrentReferenceHashMap.EntryIterator
Internal entry iterator implementation. |
| private class | ConcurrentReferenceHashMap.EntrySet
Internal entry-set implementation. |
| protected static interface | ConcurrentReferenceHashMap.Reference<
the key type K, the value type V>A reference to an |
| protected class | ConcurrentReferenceHashMap.ReferenceManager
Strategy class used to manage |
| public static enum | ConcurrentReferenceHashMap.ReferenceType
Various reference types supported by this map. |
| protected static enum | ConcurrentReferenceHashMap.Restructure
The types of restructuring that can be performed. |
| protected class | ConcurrentReferenceHashMap.Segment
A single segment used to divide the map to allow better concurrent performance. |
| private static class | ConcurrentReferenceHashMap.SoftEntryReference<K, V>
Internal |
| private abstract class | |
| private static enum | ConcurrentReferenceHashMap.TaskOption
Various options supported by a |
| private static class | ConcurrentReferenceHashMap.WeakEntryReference<K, V>
Internal |
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| private static final int | |
| private static final float | |
| private static final ConcurrentReferenceHashMap. | |
| private volatile Set | entrySet
Late binding entry set. |
| private final float | loadFactor
When the average number of references per table exceeds this value resize will be attempted. |
| private static final int | |
| private static final int | |
| private final ConcurrentReferenceHashMap. | referenceType
The reference type: SOFT or WEAK. |
| private final ConcurrentReferenceHashMap | segments
Array of segments indexed using the high order bits from the hash. |
| private final int | shift
The shift value used to calculate the size of the segments array and an index from the hash. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | ConcurrentReferenceHashMap(int
the initial capacity of the map initialCapacity)Create a new |
| public | ConcurrentReferenceHashMap(int
the initial capacity of the map initialCapacity, float the load factor. When the average number of references per table
exceeds this value resize will be attempted loadFactor)Create a new |
| public | ConcurrentReferenceHashMap(int
the initial capacity of the map initialCapacity, int the expected number of threads that will concurrently
write to the map concurrencyLevel)Create a new |
| public | ConcurrentReferenceHashMap(int
the initial capacity of the map initialCapacity, ConcurrentReferenceHashMap.the reference type used for entries (soft or weak) referenceTypeCreate a new |
| public | ConcurrentReferenceHashMap(int
the initial capacity of the map initialCapacity, float the load factor. When the average number of references per
table exceeds this value, resize will be attempted. loadFactor, int the expected number of threads that will concurrently
write to the map concurrencyLevel)Create a new |
| public | ConcurrentReferenceHashMap(int
the initial capacity of the map initialCapacity, float the load factor. When the average number of references per
table exceeds this value, resize will be attempted. loadFactor, int the expected number of threads that will concurrently
write to the map concurrencyLevel, ConcurrentReferenceHashMap.the reference type used for entries (soft or weak) referenceTypeCreate a new |
| Modifier and Type | Method and Description |
|---|---|
| protected static int | Returns: the calculated shift (use1 << shift to obtain a value)the minimum value minimumValue, int the maximum value maximumValue)Calculate a shift value that can be used to create a power-of-two value between the specified maximum and minimum values. |
| public void | clear()
Overrides java. Implements java. |
| public boolean | containsKey(Object
key whose presence in this map is to be tested key)Overrides java. Implements java. true if this map contains a mapping for the specified
key.
|
| protected ConcurrentReferenceHashMap | Returns: a new reference managerFactory method that returns the |
| private <T> T | |
| public Set | entrySet()
Implements abstract java. Implements java. Set view of the mappings contained in this map.
|
| public V | get(Object
the key whose associated value is to be returned key)Overrides java. Implements java. null if this map contains no mapping for the key.
|
| protected int | |
| protected final float | |
| public V | getOrDefault(Object
the key whose associated value is to be returned key, V the default mapping of the key defaultValue)Overrides default java. defaultValue if this map contains no mapping for the key.
|
| protected final ConcurrentReferenceHashMap. | Returns: the reference, ornull if not foundthe key (can be key, ConcurrentReferenceHashMap.null)types of restructure allowed during this call restructureReturn a |
| protected final ConcurrentReferenceHashMap | |
| private ConcurrentReferenceHashMap | |
| protected final int | |
| public boolean | isEmpty()
Overrides java. Implements java. true if this map contains no key-value mappings.
|
| public void | purgeUnreferencedEntries()
Remove any entries that have been garbage collected and are no longer referenced. |
| public V | put(K
key with which the specified value is to be associated key, V value to be associated with the specified key value)Overrides java. Implements java. |
| private V | |
| public V | putIfAbsent(K
key with which the specified value is to be associated key, V value to be associated with the specified key value)Overrides default java. Implements java. |
| public V | remove(Object
key whose mapping is to be removed from the map key)Overrides java. Implements java. |
| public boolean | remove(Object
key with which the specified value is associated key, final Object value expected to be associated with the specified key value)Overrides default java. Implements java. |
| public boolean | replace(K
key with which the specified value is associated key, final V value expected to be associated with the specified key oldValue, final V value to be associated with the specified key newValue)Overrides default java. Implements java. |
| public V | replace(K
key with which the specified value is associated key, final V value to be associated with the specified key value)Overrides default java. Implements java. |
| public int | size()
Overrides java. Implements java. |