Class ConcurrentReferenceHashMap<K,V>

java.lang.Object
java.util.AbstractMap<K,V>
org.springframework.util.ConcurrentReferenceHashMap<K,V>
Type Parameters:
K - the key type
V - the value type
All Implemented Interfaces:
ConcurrentMap<K,V>, Map<K,V>

public class ConcurrentReferenceHashMap<K,V> extends AbstractMap<K,V> implements ConcurrentMap<K,V>
A 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.

Since:
3.2
Author:
Phillip Webb, Juergen Hoeller
  • Constructor Details

    • ConcurrentReferenceHashMap

      public ConcurrentReferenceHashMap()
      Create a new ConcurrentReferenceHashMap instance.
    • ConcurrentReferenceHashMap

      public ConcurrentReferenceHashMap(int initialCapacity)
      Create a new ConcurrentReferenceHashMap instance.
      Parameters:
      initialCapacity - the initial capacity of the map
    • ConcurrentReferenceHashMap

      public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor)
      Create a new ConcurrentReferenceHashMap instance.
      Parameters:
      initialCapacity - the initial capacity of the map
      loadFactor - the load factor. When the average number of references per table exceeds this value resize will be attempted
    • ConcurrentReferenceHashMap

      public ConcurrentReferenceHashMap(int initialCapacity, int concurrencyLevel)
      Create a new ConcurrentReferenceHashMap instance.
      Parameters:
      initialCapacity - the initial capacity of the map
      concurrencyLevel - the expected number of threads that will concurrently write to the map
    • ConcurrentReferenceHashMap

      public ConcurrentReferenceHashMap(int initialCapacity, ConcurrentReferenceHashMap.ReferenceType referenceType)
      Create a new ConcurrentReferenceHashMap instance.
      Parameters:
      initialCapacity - the initial capacity of the map
      referenceType - the reference type used for entries (soft or weak)
    • ConcurrentReferenceHashMap

      public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)
      Create a new ConcurrentReferenceHashMap instance.
      Parameters:
      initialCapacity - the initial capacity of the map
      loadFactor - the load factor. When the average number of references per table exceeds this value, resize will be attempted.
      concurrencyLevel - the expected number of threads that will concurrently write to the map
    • ConcurrentReferenceHashMap

      public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, int concurrencyLevel, ConcurrentReferenceHashMap.ReferenceType referenceType)
      Create a new ConcurrentReferenceHashMap instance.
      Parameters:
      initialCapacity - the initial capacity of the map
      loadFactor - the load factor. When the average number of references per table exceeds this value, resize will be attempted.
      concurrencyLevel - the expected number of threads that will concurrently write to the map
      referenceType - the reference type used for entries (soft or weak)
  • Method Details