Java Reference
In-Depth Information
Atomically remove the entry for
key
if it currently maps to
value
. Returns
true
if the entry was removed. (Optional if the
map does not support
remove
)
public boolean
replace(K key, V oldValue, V newValue)
Atomically replaces the entry for
key
only if it currently maps
to
oldValue
. Returns
true
if the entry was replaced. (Optional
if the map does not support
put
)
public V
replace(K key, V value)
Atomically replaces the mapping for
key
if and only if a map-
ping currently exists. The old value mapped to
key
is returned,
or
null
if the
key
was not presentbut be aware that
null
may
be a legitimate value for some maps. (Optional if the map
does not support
put
)
The
ConcurrentLinkedQueue<E>
class provides an unbounded thread-safe
queue based on a linked node representation. Operations on the queue
are highly concurrent and do not utilize locks. Because of the concurrent
nature an operation like
size
requires a complete traversal of the queue
and so is quite expensivehowever, knowing the size that a concur-
rently changing queue used to be is seldom, if ever, useful. The iterator
provided by
ConcurrentLinkedQueue
is weakly consistent, it guarantees to
traverse the elements that existed when the iterator was created, but
may not reflect subsequent additions.
The
CopyOnWriteArrayList<E>
is a thread-safe variant of
ArrayList
. It al-
lows iteration to be done over a snapshot of the contents without ac-
tually making a copy of the original list. Copies are made only when
someone modifies the listhence the name "copy on write." This makes a
very efficient structure for lists that are read much more frequently than
they are changed. Because the iterator sees a snapshot of the elements,
it can never fail; but it does not support the
remove
operation.