java.util.concurrent.ConcurrentHashMap
with better scaling properties and generally lower costs to mutate the Map.
It provides identical correctness properties as ConcurrentHashMap. All
operations are non-blocking and multi-thread safe, including all update
operations. NonBlockingHashMap scales substatially better than
java.util.concurrent.ConcurrentHashMap for high update rates, even with a
large concurrency factor. Scaling is linear up to 768 CPUs on a 768-CPU
Azul box, even with 100% updates or 100% reads or any fraction in-between.
Linear scaling up to all cpus has been observed on a 32-way Sun US2 box,
32-way Sun Niagra box, 8-way Intel box and a 4-way Power box.
This class obeys the same functional specification as java.util.Hashtable , and includes versions of methods corresponding to
each method of Hashtable. However, even though all operations are
thread-safe, operations do not entail locking and there is
not any support for locking the entire table in a way that
prevents all access. This class is fully interoperable with
Hashtable in programs that rely on its thread safety but not on
its synchronization details.
Operations (including put) generally do not block, so may
overlap with other update operations (including other puts and
removes). Retrievals reflect the results of the most recently
completed update operations holding upon their onset. For
aggregate operations such as putAll, concurrent retrievals may
reflect insertion or removal of only some entries. Similarly, Iterators
and Enumerations return elements reflecting the state of the hash table at
some point at or since the creation of the iterator/enumeration. They do
not throw ConcurrentModificationException. However,
iterators are designed to be used by only one thread at a time.
Very full tables, or tables with high reprobe rates may trigger an internal resize operation to move into a larger table. Resizing is not terribly expensive, but it is not free either; during resize operations table throughput may drop somewhat. All threads that visit the table during a resize will 'help' the resizing but will still be allowed to complete their operation before the resize is finished (i.e., a simple 'get' operation on a million-entry table undergoing resizing will not need to block until the entire million entries are copied).
This class and its views and iterators implement all of the
optional methods of the Map and Iterator
interfaces.
Like Hashtable but unlike HashMap, this class
does not allow null to be used as a key or value.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private class | |
| private static class | |
| private class | |
| private class | |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private transient Object[] | |
| private static final long | |
| private transient long | |
| private static final int | |
| private static final int | |
| private transient ConcurrentAutoTable | |
| private static final Object | |
| private static final int | |
| private static final int | |
| private static final Object | |
| private static final int | |
| private static final long | |
| private static final NonBlockingIdentityHashMap. | |
| private static final Object |
| Access | Constructor and Description |
|---|---|
| public | NonBlockingIdentityHashMap()
Create a new NonBlockingHashMap with default minimum size (currently set to 8 K/V pairs or roughly 84 bytes on a standard 32-bit JVM). |
| public | NonBlockingIdentityHashMap(final int initial_sz)
Create a new NonBlockingHashMap with initial room for the given number of elements, thus avoiding internal resizing operations to reach an appropriate size. |
| Modifier and Type | Method and Description |
|---|---|
| private static final boolean | |
| private final boolean | |
| private static final boolean | |
| private static final NonBlockingIdentityHashMap. | |
| public void | clear()
Overrides java. Implements java. |
| public Object | Returns: a clone of the hashtable.Overrides java. |
| public boolean | |
| public boolean | Returns: true if the key is in the table using the equals methodkey whose presence in this map is to be tested key)Overrides java. Implements java. |
| public boolean | Returns: true if this map maps one or more keys to the specified valuevalue whose presence in this map is to be tested val)Overrides java. Implements java. Note This method requires a full internal traversal of the
hash table and is much slower than |
| public Enumeration | Returns: an enumeration of the values in this tableReturns an enumeration of the values in this table. |
| public Set | entrySet()
Implements abstract java. Implements java. Set view of the mappings contained in this map.
|
| public TypeV | get(Object
the key whose associated value is to be returned key)Overrides java. Implements java. null
if this map contains no mapping for the key.
|
| private static final Object | get_impl(final NonBlockingIdentityHashMap<TypeK, TypeV> topmap, final Object[] kvs, final Object key)
|
| private static final int | |
| private static final int[] | |
| private final Object[] | |
| private final void | |
| protected final void | |
| public boolean | Returns: size() == 0Overrides java. Implements java. |
| private static final Object | |
| public Enumeration | Returns: an enumeration of the keys in this tableReturns an enumeration of the keys in this table. |
| public Set | keySet()
Overrides java. Implements java. Set view of the keys contained in this map.
|
| private static final int | |
| public final void | |
| private final void | |
| private final void | |
| public TypeV | Returns: the previous value associated with key, or null if there was no mapping for keykey with which the specified value is to be associated key, TypeV value to be associated with the specified key val)Overrides java. Implements java. |
| public void | putAll(Map<? extends TypeK, ? extends TypeV>
mappings to be stored in this map m)Overrides java. Implements java. |
| public TypeV | Returns: the previous value associated with the specified key, or null if there was no mapping for the keykey with which the specified value is to be associated key, TypeV value to be associated with the specified key val)Overrides default java. Implements java. put if-and-only-if the key is not mapped.
|
| private final TypeV | |
| private static final Object | putIfMatch(final NonBlockingIdentityHashMap<TypeK, TypeV> topmap, final Object[] kvs, final Object key, final Object putval, final Object expVal)
|
| private static long | |
| private void | |
| protected void | |
| public TypeV | Returns: the previous value associated with key, or null if there was no mapping for keykey whose mapping is to be removed from the map key)Overrides java. Implements java. |
| public boolean | remove(Object
key with which the specified value is associated key, Object value expected to be associated with the specified key val)Overrides default java. Implements java. remove(Object) if-and-only-if the key is mapped
to a value which is equals to the given value.
|
| public TypeV | replace(TypeK
key with which the specified value is associated key, TypeV value to be associated with the specified key val)Overrides default java. Implements java. put(key,val) if-and-only-if the key is
mapped to some value already.
|
| public boolean | replace(TypeK
key with which the specified value is associated key, TypeV value expected to be associated with the specified key oldValue, TypeV value to be associated with the specified key newValue)Overrides default java. Implements java. put(key,newValue) if-and-only-if the key is
mapped a value which is equals to oldValue.
|
| private static final int | |
| public long | |
| public int | Returns: the number of key-value mappings in this mapOverrides java. Implements java. |
| public String | Returns: a string representation of this mapOverrides java. |
| private static final Object | |
| public Collection | values()
Overrides java. Implements java. Collection view of the values contained in this map.
|
| private void |