ConcurrentReferenceHashMap

A ConcurrentHashMap variant 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 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.

Author

Phillip Webb

Juergen Hoeller

Brian Clozel

Since

3.2

Parameters

<K>

the key type

<V>

the value type

Constructors

Link copied to clipboard
constructor()
Create a new ConcurrentReferenceHashMap instance.
constructor(initialCapacity: Int)
Create a new ConcurrentReferenceHashMap instance.
constructor(initialCapacity: Int, loadFactor: Float)
Create a new ConcurrentReferenceHashMap instance.
constructor(initialCapacity: Int, concurrencyLevel: Int)
Create a new ConcurrentReferenceHashMap instance.
constructor(initialCapacity: Int, referenceType: ConcurrentReferenceHashMap.ReferenceType)
Create a new ConcurrentReferenceHashMap instance.
constructor(initialCapacity: Int, loadFactor: Float, concurrencyLevel: Int)
Create a new ConcurrentReferenceHashMap instance.
constructor(initialCapacity: Int, loadFactor: Float, concurrencyLevel: Int, referenceType: ConcurrentReferenceHashMap.ReferenceType)
Create a new ConcurrentReferenceHashMap instance.

Types

Link copied to clipboard
Various reference types supported by this map.

Functions

Link copied to clipboard
open fun clear()
Link copied to clipboard
@Nullable
open fun compute(@Nullable key: @Nullable K, remappingFunction: BiFunction<in K, in V, out V>): @Nullable V
Link copied to clipboard
@Nullable
open fun computeIfAbsent(@Nullable key: @Nullable K, mappingFunction: (in K) -> out V): @Nullable V
Link copied to clipboard
@Nullable
open fun computeIfPresent(@Nullable key: @Nullable K, remappingFunction: BiFunction<in K, in V, out V>): @Nullable V
Link copied to clipboard
open fun containsKey(@Nullable key: @Nullable Any): Boolean
Link copied to clipboard
open fun containsValue(value: Any): Boolean
Link copied to clipboard
open fun <K, V> copyOf(map: Map<out K, out V>): Map<K, V>
Link copied to clipboard
open fun <K, V> entry(k: K, v: V): Map.Entry<K, V>
Link copied to clipboard
open fun entrySet(): Set<Map.Entry<K, V>>
Link copied to clipboard
open fun equals(o: Any): Boolean
Link copied to clipboard
open fun forEach(action: BiConsumer<in K, in V>)
Link copied to clipboard
@Nullable
open fun get(@Nullable key: @Nullable Any): @Nullable V
Link copied to clipboard
@Nullable
open fun getOrDefault(@Nullable key: @Nullable Any, @Nullable defaultValue: @Nullable V): @Nullable V
Link copied to clipboard
open fun hashCode(): Int
Link copied to clipboard
open fun isEmpty(): Boolean
Link copied to clipboard
open fun keySet(): Set<K>
Link copied to clipboard
@Nullable
open fun merge(@Nullable key: @Nullable K, @Nullable value: @Nullable V, remappingFunction: BiFunction<in V, in V, out V>): @Nullable V
Link copied to clipboard
open fun <K, V> of(): Map<K, V>
Link copied to clipboard
open fun <K, V> ofEntries(entries: Array<Map.Entry<out K, out V>>): Map<K, V>
Link copied to clipboard
Remove any entries that have been garbage collected and are no longer referenced.
Link copied to clipboard
@Nullable
open fun put(@Nullable key: @Nullable K, @Nullable value: @Nullable V): @Nullable V
Link copied to clipboard
open fun putAll(m: Map<out K, out V>)
Link copied to clipboard
@Nullable
open fun putIfAbsent(@Nullable key: @Nullable K, @Nullable value: @Nullable V): @Nullable V
Link copied to clipboard
@Nullable
open fun remove(@Nullable key: @Nullable Any): @Nullable V
open fun remove(@Nullable key: @Nullable Any, @Nullable value: @Nullable Any): Boolean
Link copied to clipboard
@Nullable
open fun replace(@Nullable key: @Nullable K, @Nullable value: @Nullable V): @Nullable V
open fun replace(@Nullable key: @Nullable K, @Nullable oldValue: @Nullable V, @Nullable newValue: @Nullable V): Boolean
Link copied to clipboard
open fun replaceAll(function: BiFunction<in K, in V, out V>)
Link copied to clipboard
open fun size(): Int
Link copied to clipboard
open fun toString(): String
Link copied to clipboard
open fun values(): Collection<V>