简体   繁体   English

LinkedBlockingQueue-无界-放置阻止?

[英]LinkedBlockingQueue - unbounded - put blocking?

I have 2 simple questions here. 我在这里有两个简单的问题。 I have a LinkedBlockingQueue which I create simply as 我有一个LinkedBlockingQueue,我可以简单地创建为

new LinkedBlockingQueue()

So I think this guarantees that is unbounded, is that right? 所以我认为这保证了无限,对吗?
If indeed so, is it right to say that the method put can never block when called on this queue instance? 如果确实如此,是否可以正确地说出在此队列实例上调用时put的方法永远不会阻塞?

The Java docs specify that a no-arg constructor invocation will result in a capacity of Integer.MAX_VALUE , which is large but not actually infinite, so the queue is bounded (but for practical purposes, it might as well not be). Java文档指定无参数构造函数调用将导致Integer.MAX_VALUE的容量,该容量很大,但实际上不是无限的,因此队列是有界的(但出于实际目的,也可能不是)。

The put method will block only if space needs to become available, meaning it will block if the queue already has a number of elements equal to capacity. put方法仅在需要空间可用时才阻塞,这意味着如果队列中已有数量等于容量的元素,则put方法将阻塞。

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

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