A
BQ is a Q whose put method blocks if the Q has reached its maximum
capacity and its get method blocks if the Q is already empty.
Types of
BlockingQueue
Apart
from normal synchronized put method, BQ also supports blocking of
threads if they try to read the Q when empty or try to write to the Q
when its full.
It
has following flavors:
ArrayBlockingQueue
LinkedBlockingQueue
PriorityBlockingQueue
DelayQueue:
Same as #1 except that it accepts objects implementing Delayed
interface
only. Delayed mandates implementation of getDelay(TimeUnit)
which should return the remaining delay associated with this object.
So every object in DelayQueue is available only after the delay
specified with that object has passed.
SynchronousQueue:
This is a BQ having capacity of only one element. Due to capacity of
one element only, it forces single production followed by single
consumption.
LinkedTransferQueue:
This is same as BQ except that it offers function which can make a
producer wait for the consumer to consume it. This is done by adding
methods:
void
transfer(T obj) : blocks the producer till transfer happens
boolean
tryTransfer (T obj) : returns immediately indicating if the
transfer happened or not.
boolean
tryTransfer (T obj, long timeCount, TimeUnit unit) : same as above
but with a time-out.
Got a thought to share or found a bug in the code? We'd love to hear from you: