WeakReferenceThreadMap@Private
public class WeakReferenceMap<K,V>
extends java.lang.Object
create(Object) for the concurrency semantics on entry creation.| Constructor | Description |
|---|---|
WeakReferenceMap(java.util.function.Function<? super K,? extends V> factory,
java.util.function.Consumer<? super K> referenceLost) |
instantiate.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
clear() |
Clear all entries.
|
boolean |
containsKey(K key) |
Does the map have a valid reference for this object?
no-side effects: there's no attempt to notify or cleanup
if the reference is null.
|
V |
create(K key) |
Create a new instance under a key.
|
V |
get(K key) |
Get the value, creating if needed.
|
long |
getEntriesCreatedCount() |
Get count of entries created on demand.
|
long |
getReferenceLostCount() |
Get count of references lost as detected
during prune() or get() calls.
|
java.lang.ref.WeakReference<V> |
lookup(K key) |
look up the value, returning the possibly empty weak reference
to a value, or null if no value was found.
|
int |
prune() |
Prune all null weak references, calling the referenceLost
callback for each one.
|
V |
put(K key,
V value) |
Put a value under the key.
|
V |
remove(K key) |
Remove any value under the key.
|
protected V |
resolve(java.lang.ref.WeakReference<V> r) |
Given a possibly null weak reference, resolve
its value.
|
int |
size() |
Map size.
|
java.lang.String |
toString() |
public java.lang.String toString()
toString in class java.lang.Objectpublic int size()
public void clear()
public java.lang.ref.WeakReference<V> lookup(K key)
key - key to look uppublic V get(K key)
key - key.public V create(K key)
The instance is created, added to the map and then the map value retrieved. This ensures that the reference returned is that in the map, even if there is more than one entry being created at the same time. If that race does occur, it will be logged the first time it happens for this specific map instance.
HADOOP-18456 highlighted the risk of a concurrent GC resulting a null value being retrieved and so returned. To prevent this:
key - keypublic V put(K key, V value)
key - keyvalue - valuepublic V remove(K key)
key - keypublic boolean containsKey(K key)
key - key to look upprotected V resolve(java.lang.ref.WeakReference<V> r)
r - reference to resolvepublic int prune()
public final long getReferenceLostCount()
public final long getEntriesCreatedCount()
Copyright © 2008–2025 Apache Software Foundation. All rights reserved.