Java Reference
In-Depth Information
capacity, not even a capacity of one, so you cannot peek into a
synchronous queue, nor can you iterate through it. From the per-
spective of most of the collection methods a synchronous queue
acts like an empty collection.
•
DelayQueue
A specialized unbounded blocking queue of
Delayed
ele-
ments. The
Delayed
interface has a single method,
getdelay
, which
takes a
TimeUnit
constant and returns the delay in that time unit.
A
Delayed
element cannot be removed from a
DelayQueue
until its
delay has expired. The head of a delay queue is that element
whose delay expired furthest in the past. If no elements have a
delay that has passed then the head is
null
. It provides an iterat-
or that is thread-safe but fail-fast.
In addition to the thread-safe blocking queues,
java.util.concurrent
provides a number of other concurrent collections.
ConcurrentHashMap
provides a hash map implementation that allows for
fully concurrent retrievals and up to a set number of concurrent inser-
tions. Although all operations are thread-safe, they do not involve lock-
ing, and there is no way to externally synchronize the map to provide
atomic sequences of operations. Because of this, some extra support
is needed to do things like inserting a value in the map only if it is
not present. The
ConcurrentMap<K,V>
interface, implemented by
Concur-
rentHashMap
, defines a number of such methods:
public V
putIfAbsent(K key, V value)
Atomically stores the given value in the map only if a mapping
for
key
does not currently exist. 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
)
public boolean
remove(Object key, Object value)