public class ConcurrentLinkedHashMap<K,V> extends AbstractMap<K,V> implements ConcurrentMap<K,V>, Serializable
ConcurrentMap with a doubly-linked list running through its
entries.
This class provides the same semantics as a ConcurrentHashMap in
terms of iterators, acceptable keys, and concurrency characteristics, but
perform slightly worse due to the added expense of maintaining the linked
list. It differs from LinkedHashMap in that it does not
provide predictable iteration order.
This map is intended to be used for caches and provides the following
eviction policies: LinkedHashMap evicting in access order.| Modifier and Type | Class and Description |
|---|---|
static interface |
ConcurrentLinkedHashMap.EvictionListener<K,V>
A listener registered for notification when an entry is evicted.
|
static class |
ConcurrentLinkedHashMap.EvictionPolicy
The replacement policy to apply to determine which entry to discard to
when the capacity has been reached.
|
AbstractMap.SimpleImmutableEntry<K,V>| Constructor and Description |
|---|
ConcurrentLinkedHashMap(ConcurrentLinkedHashMap.EvictionPolicy policy,
int maximumCapacity,
ConcurrentLinkedHashMap.EvictionListener<K,V>... listeners)
Creates a new, empty, unbounded map with the specified maximum capacity
and the default concurrencyLevel.
|
ConcurrentLinkedHashMap(ConcurrentLinkedHashMap.EvictionPolicy policy,
int maximumCapacity,
int concurrencyLevel,
ConcurrentLinkedHashMap.EvictionListener<K,V>... listeners)
Creates a new, empty, unbounded map with the specified maximum capacity
and concurrency level.
|
| Modifier and Type | Method and Description |
|---|---|
int |
capacity()
Retrieves the maximum capacity of the map.
|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
V |
get(Object key) |
V |
put(K key,
V value) |
V |
putIfAbsent(K key,
V value) |
V |
remove(Object key) |
boolean |
remove(Object key,
Object value) |
V |
replace(K key,
V value) |
boolean |
replace(K key,
V oldValue,
V newValue) |
void |
setCapacity(int capacity)
Sets the maximum capacity of the map and eagerly evicts entries until the
it shrinks to the appropriate size.
|
int |
size() |
clone, equals, hashCode, isEmpty, keySet, putAll, toString, valuespublic ConcurrentLinkedHashMap(ConcurrentLinkedHashMap.EvictionPolicy policy, int maximumCapacity, ConcurrentLinkedHashMap.EvictionListener<K,V>... listeners)
policy - The eviction policy to apply when the size exceeds the maximum
capacity.maximumCapacity - The maximum capacity to coerces to. The size may exceed it
temporarily.listeners - The listeners registered for notification when an entry is
evicted.public ConcurrentLinkedHashMap(ConcurrentLinkedHashMap.EvictionPolicy policy, int maximumCapacity, int concurrencyLevel, ConcurrentLinkedHashMap.EvictionListener<K,V>... listeners)
policy - The eviction policy to apply when the size exceeds the maximum
capacity.maximumCapacity - The maximum capacity to coerces to. The size may exceed it
temporarily.concurrencyLevel - The estimated number of concurrently updating threads. The
implementation performs internal sizing to try to accommodate
this many threads.listeners - The listeners registered for notification when an entry is
evicted.public void setCapacity(int capacity)
capacity - The maximum capacity of the map.public int capacity()
public int size()
public void clear()
public boolean containsKey(Object key)
containsKey in interface Map<K,V>containsKey in class AbstractMap<K,V>public boolean containsValue(Object value)
containsValue in interface Map<K,V>containsValue in class AbstractMap<K,V>public V putIfAbsent(K key, V value)
putIfAbsent in interface ConcurrentMap<K,V>public boolean remove(Object key, Object value)
remove in interface ConcurrentMap<K,V>public boolean replace(K key, V oldValue, V newValue)
replace in interface ConcurrentMap<K,V>Copyright © 2014 Molindo GmbH. All Rights Reserved.