O'Reilly logo
  • Varun Prasad thinks this is interesting:

The java.util.concurrent package supplies several variations of blocking queues. A LinkedBlockingQueue is based on a linked list, and an ArrayBlockingQueue uses a circular array.


Cover of Core Java® for the Impatient


ConcurrentLinkedQueue means no locks are taken (i.e. no synchronized(this) or Lock.lock calls). It will use a CAS - Compare and Swap operation during modifications to see if the head/tail node is still the same as when it started. If so, the operation succeeds. If the head/tail node is different, it will spin around and try again.

LinkedBlockingQueue will take a lock before any modification. So your offer calls would block until they get the lock. You can use the offer overload that takes a TimeUnit to say you are only willing to wait X amount of time before abandoning the add (usually good for message type queues where the message is stale after X number of milliseconds).

Fairness means that the Lock implementation will...