翻译
类注释
1 | /** |
示例
1 | * class Producer implements Runnable { |
1 |
|
源码
1 | public interface BlockingQueue<E> extends Queue<E> { |
总结
- 是一种线程安全的队列
- 一般用于这样的场景:一个线程生产对象,另一个线程来消耗对象
- 不能向BlockingQueue中插入null,否则会抛出NullPointerException异常
operation | Throws Exception | Special Value | Blocks新 | Times Out新 |
---|---|---|---|---|
Insert | add(o) | offer(o) | put(o) 阻塞 | offer(o, timeout, timeunit) |
Remove | remove(o) | poll() | take() 阻塞 | poll(timeout, timeunit) |
Examine | element() | peek() |
本站评论搭建在 Github Issue 上,请点击进行评论。