public class WeakConcurrentMap<K,V> extends ReferenceQueue<K> implements Runnable, Iterable<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 |
|---|---|
static class |
WeakConcurrentMap.WithInlinedExpunction<K,V>
A
WeakConcurrentMap where stale entries are removed as a side effect of interacting with this map. |
| Constructor and Description |
|---|
WeakConcurrentMap(boolean cleanerThread) |
WeakConcurrentMap(boolean cleanerThread,
boolean reuseKeys) |
| 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) |
Thread |
getCleanerThread() |
V |
getIfPresent(K key) |
Iterator<Map.Entry<K,V>> |
iterator() |
V |
put(K key,
V value) |
V |
putIfAbsent(K key,
V value) |
V |
putIfProbablyAbsent(K key,
V value) |
V |
remove(K key) |
void |
run() |
poll, remove, removeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic WeakConcurrentMap(boolean cleanerThread)
cleanerThread - true if a thread should be started that removes stale entries.public WeakConcurrentMap(boolean cleanerThread,
boolean reuseKeys)
cleanerThread - true if a thread should be started that removes stale entries.reuseKeys - true if the lookup keys should be reused via a ThreadLocal.
Note that setting this to true may result in class loader leaks.
See isPersistentClassLoader(ClassLoader) for more details.public V get(K key)
key - The key of the entry.public V getIfPresent(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 putIfAbsent(K key, V value)
key - The key of the entry.value - The value of the entry.null if it does not exist.public V putIfProbablyAbsent(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 Thread getCleanerThread()
null if no such thread was set.public void expungeStaleEntries()
public int approximateSize()
Copyright © 2016–2019. All rights reserved.