java.lang.Object | ||
↳ | com.atlassian.util.concurrent.CopyOnWriteMap<K, V> | |
↳ | com.atlassian.plugin.util.concurrent.CopyOnWriteMap<K, V> |
This class is deprecated.
since 2.5.0 please use the
com.atlassian.util.concurrent.CopyOnWriteMap instead as
it has some important features and some bug fixes. This version
is no longer maintained.
A thread-safe variant of Map in which all mutative operations (the "destructive" operations described by Map put, remove and so on) are implemented by making a fresh copy of the underlying map.
This is ordinarily too costly, but may be more efficient than
alternatives when traversal operations vastly out-number mutations, and is
useful when you cannot or don't want to synchronize traversals, yet need to
preclude interference among concurrent threads. The "snapshot" style
iterators on the collections returned by entrySet()
,
keySet()
and values()
use a reference to the internal map
at the point that the iterator was created. This map never changes during the
lifetime of the iterator, so interference is impossible and the iterator is
guaranteed not to throw ConcurrentModificationException. The
iterators will not reflect additions, removals, or changes to the list since
the iterator was created. Removing elements via these iterators is not
supported. The mutable operations on these collections (remove, retain etc.)
are supported but as with the Map
interface, add and addAll are not
and throw UnsupportedOperationException
.
The actual copy is performed by an abstract copy(Map)
method. The
method is responsible for the underlying Map implementation (for instance a
HashMap, TreeMap, LinkedHashMap etc.) and therefore
the semantics of what this map will cope with as far as null keys and values,
iteration ordering etc. See the note below about suitable candidates for
underlying Map implementations
There are supplied implementations for the common Collections Map
implementations via the CopyOnWriteMaps static factory methods.
Collection views of the keys, values and entries are modifiable and will cause a copy.
Please note that the thread-safety guarantees are limited to
the thread-safety of the non-mutative (non-destructive) operations of the
underlying map implementation. For instance some implementations such as
WeakHashMap and LinkedHashMap with access ordering are
actually structurally modified by the get(Object)
method and are
therefore not suitable candidates as delegates for this class.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new
CopyOnWriteMap with the supplied Map to
initialize the values. | |||||||||||
Create a new empty
CopyOnWriteMap . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a new
CopyOnWriteMap with an underlying HashMap. | |||||||||||
Creates a new
CopyOnWriteMap with an underlying HashMap
using the supplied map as the initial values. | |||||||||||
Creates a new
CopyOnWriteMap with an underlying
LinkedHashMap. | |||||||||||
Creates a new
CopyOnWriteMap with an underlying
LinkedHashMap using the supplied map as the initial values. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.atlassian.util.concurrent.CopyOnWriteMap
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.util.Map
| |||||||||||
From interface
java.util.concurrent.ConcurrentMap
|
Create a new CopyOnWriteMap
with the supplied Map
to
initialize the values.
map | the initial map to initialize with |
---|
Creates a new CopyOnWriteMap
with an underlying HashMap.
Creates a new CopyOnWriteMap
with an underlying HashMap
using the supplied map as the initial values.
Creates a new CopyOnWriteMap
with an underlying
LinkedHashMap. Iterators for this map will be return elements in
insertion order.
Creates a new CopyOnWriteMap
with an underlying
LinkedHashMap using the supplied map as the initial values.
Iterators for this map will be return elements in insertion order.