Art_Rebel Art_Rebel - 1 year ago 175
Java Question

Is LinkedTransferQueue blocking or not-blocking queue?

I read about concurrent queue in java, and i received confusion about LinkedTransferQueue. What is type of LinkedTransferQueue (is it blocking or not-blocking queue)? I have read that LinkedTransferQueue uses a CAS (compare and swap) approach and park method from Unsafe, and consists from nodes and pointers like ConcurrentLinkedQueue, it pushed on idea that it's a non-blocking queue. But interface TransferQueue extends BlockingQueue. It looks ambiguous. In the end, is LinkedTransferQueue blocking or not-blocking queue?

Answer Source

The LinkedTransferQueue is an unbounded queue so though it is BlockingQueue it will never actually reach the common producer/consumer patterns normal BlockingQueue implementations may achieve.

So, is it or isn't it blocking? It actually depends on the operation. For example, a few are listed below.

Non-blocking operations:

  • offer
  • put
  • add
  • poll
  • tryTransfer

Blocking operations:

  • take
  • transfer

Point is, if an operation can achieve without blocking it will. Since the LinkedTransferQueue is forced to be unbounded, it can get away with both blocking and non-blocking operations.

If interested, I found this out by going through the Java 8 implementation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download