public final class QueueUtil extends Object
Modifier and Type | Method and Description |
---|---|
static int |
drainQueue(Queue<?> queue)
Drains the provided queue by the size of the queue as it is known
upfront draining.
|
static int |
drainQueue(Queue<?> queue,
int elementsToDrain)
Drains the provided queue by the count provided in
elementsToDrain . |
public static int drainQueue(Queue<?> queue)
The rational for using this method is the same as for using
Collection.clear()
: to remove all the elements from the queue.
There are two major differences to highlight:
Collection.clear()
doesn't.Collection.clear()
is in conditions where the queue is written
concurrently without blocking the writer threads for the time of
draining the queue and the caller needs to know the number of
elements removed from the queue.queue
- The queue to be drainedpublic static int drainQueue(Queue<?> queue, int elementsToDrain)
elementsToDrain
.queue
- The queue to be drainedelementsToDrain
- The number of elements to be drained from
the queueCopyright © 2020 Hazelcast, Inc.. All Rights Reserved.