BlockingQueue的异常Queue full

生产异常日志:java.lang.IllegalStateException: Queue full

原因:当使用add方法的时候,队列满了,再放入元素,就会报这个异常

解决方法:将add方法替换成put方法,队列变成阻塞队列。

 

引用java doc:

BlockingQueue methods come in four forms, with different ways of handling operations that cannot be satisfied immediately, but may be satisfied at some point in the future: one throws an exception, the second returns a special value (either null or false, depending on the operation), the third blocks the current thread indefinitely until the operation can succeed, and the fourth blocks for only a given maximum time limit before giving up. These methods are summarized in the following table: 

  Throws exception Special value Blocks Times out
Insert add(e) offer(e) put(e) offer(e, time, unit)
Remove remove() poll() take() poll(time, unit)
Examine element() peek() not applicable not applicable

 

 

转载于:https://www.cnblogs.com/mongoo/archive/2013/04/10/3012729.html

你可能感兴趣的:(BlockingQueue的异常Queue full)