简体   繁体   English

LinkedTransferQueue是阻塞队列还是非阻塞队列?

[英]Is LinkedTransferQueue blocking or not-blocking queue?

I read about concurrent queue in java, and i received confusion about LinkedTransferQueue. 我阅读了有关Java中的并发队列的信息,并对LinkedTransferQueue感到困惑。 What is type of LinkedTransferQueue (is it blocking or not-blocking queue)? LinkedTransferQueue是什么类型(它是阻塞队列还是非阻塞队列)? 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. 我已经读到LinkedTransferQueue使用Unsafe的CAS(比较和交换)方法和停放方法,并由诸如ConcurrentLinkedQueue之类的节点和指针组成,它提出了一个非阻塞队列的想法。 But interface TransferQueue extends BlockingQueue . 但是接口TransferQueue扩展了BlockingQueue It looks ambiguous. 看起来模棱两可。 In the end, is LinkedTransferQueue blocking or not-blocking queue? 最后,LinkedTransferQueue是阻塞队列还是非阻塞队列?

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. LinkedTransferQueue是一个无界队列,因此,尽管它是BlockingQueue ,但它实际上不会达到正常的BlockingQueue实现可能实现的常见生产者/消费者模式。

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. 由于LinkedTransferQueue被强制为无限制的,因此可以通过阻塞和非阻塞操作逃脱。

If interested, I found this out by going through the Java 8 implementation. 如果有兴趣,我可以通过Java 8实现来发现。

From the Javadoc : Javadoc

An optionally-bounded blocking queue based on linked nodes. 基于链接节点的可选绑定的阻塞队列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM