public class WeakConcurrentMap<K,V>
extends java.lang.ref.ReferenceQueue<K>
implements java.lang.Runnable, java.lang.Iterable<java.util.Map.Entry<K,V>>
A thread-safe map with weak keys. Entries are based on a key's system hash code and keys are considered equal only by reference equality.
This class does not implement theMap
interface because this implementation is incompatible
with the map contract. While iterating over a map's entries, any key that has not passed iteration is referenced non-weakly.Modifier and Type | Class and Description |
---|---|
private class |
WeakConcurrentMap.EntryIterator |
private static class |
WeakConcurrentMap.LatentKey<T> |
private class |
WeakConcurrentMap.SimpleEntry |
private static class |
WeakConcurrentMap.WeakKey<T> |
static class |
WeakConcurrentMap.WithInlinedExpunction<K,V>
A
WeakConcurrentMap where stale entries are removed as a side effect of interacting with this map. |
Modifier and Type | Field and Description |
---|---|
private static java.util.concurrent.atomic.AtomicLong |
ID |
java.util.concurrent.ConcurrentMap<WeakConcurrentMap.WeakKey<K>,V> |
target |
private java.lang.Thread |
thread |
Constructor and Description |
---|
WeakConcurrentMap(boolean cleanerThread) |
Modifier and Type | Method and Description |
---|---|
int |
approximateSize()
Returns the approximate size of this map where the returned number is at least as big as the actual number of entries.
|
void |
clear()
Clears the entire map.
|
boolean |
containsKey(K key) |
protected V |
defaultValue(K key)
Creates a default value.
|
void |
expungeStaleEntries()
Cleans all unused references.
|
V |
get(K key) |
java.lang.Thread |
getCleanerThread() |
java.util.Iterator<java.util.Map.Entry<K,V>> |
iterator() |
V |
put(K key,
V value) |
V |
remove(K key) |
void |
run() |
private static final java.util.concurrent.atomic.AtomicLong ID
public final java.util.concurrent.ConcurrentMap<WeakConcurrentMap.WeakKey<K>,V> target
private final java.lang.Thread thread
public WeakConcurrentMap(boolean cleanerThread)
cleanerThread
- true
if a thread should be started that removes stale entries.public V get(K key)
key
- The key of the entry.public boolean containsKey(K key)
key
- The key of the entry.true
if the key already defines a value.public V put(K key, V value)
key
- The key of the entry.value
- The value of the entry.null
if it does not exist.public V remove(K key)
key
- The key of the entry.null
if it does not exist.public void clear()
protected V defaultValue(K key)
key
- The key for which to create a default value.null
for not defining a default value.public java.lang.Thread getCleanerThread()
null
if no such thread was set.public void expungeStaleEntries()
public int approximateSize()
public void run()
run
in interface java.lang.Runnable