简体   繁体   English

LinkedBlockingQueue - java - 队列已满

[英]LinkedBlockingQueue - java - queue full

I have a linked blocking queue around which I coordinate 我有一个链接的阻塞队列,我在其周围进行协调
the work of 20 consumer threads and 20 producer threads. 20个消费者线程和20个生产者线程的工作。
The capacity is 10 of the queue (I am just testing currently). 容量是队列中的10个(我目前正在测试)。

But instead of blocking, when I put into a full queue, 但是当我进入一个完整的队列时,而不是阻塞,
I get this error below. 我在下面收到此错误。 Why so? 为什么这样? The JavaDoc says JavaDoc说
the queue should be blocking in this case. 在这种情况下,队列应该是阻塞的。
Am I misunderstanding something? 我误会了什么吗?

java.lang.IllegalStateException: Queue full
    at java.util.AbstractQueue.add(AbstractQueue.java:98)
    at java.util.AbstractQueue.addAll(AbstractQueue.java:187)

You need to use put on the LinkedBlockingQueue . 你需要在LinkedBlockingQueue上使用put put will wait as long as necessary until space is available. put将在必要时等待,直到空间可用。 offer will return a boolean indicating success or failure. offer将返回指示成功或失败的布尔值。

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

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