简体   繁体   中英

LinkedBlockingQueue - java - queue full

I have a linked blocking queue around which I coordinate
the work of 20 consumer threads and 20 producer threads.
The capacity is 10 of the queue (I am just testing currently).

But instead of blocking, when I put into a full queue,
I get this error below. Why so? The JavaDoc says
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 . put will wait as long as necessary until space is available. offer will return a boolean indicating success or failure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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