The PriorityBlockingQueue class implements the BlockingQueue interface. Read the BlockingQueue text for more information about the interface.
The PriorityBlockingQueue is an unbounded concurrent queue. It uses the same ordering rules as thejava.util.PriorityQueue class. You cannot insert null into this queue.
All elements inserted into the PriorityBlockingQueue must implement the java.lang.Comparable interface. The elements thus order themselves according to whatever priority you decide in your Comparableimplementation.
Notice that the PriorityBlockingQueue does not enforce any specific behaviour for elements that have equal priority (compare() == 0).
Also notice, that in case you obtain an Iterator from a PriorityBlockingQueue, the Iterator does not guarantee to iterate the elements in priority order.
Here is an example of how to use the PriorityBlockingQueue:
BlockingQueue queue = new PriorityBlockingQueue();
//String implements java.lang.Comparable
queue.put("Value");
String value = queue.take();
本文介绍了PriorityBlockingQueue类,它是基于优先级的并发队列实现,遵循java.util.PriorityQueue的规则,不允许插入null元素。所有元素必须实现java.lang.Comparable接口以确定其优先级。文章还提供了使用PriorityBlockingQueue的基本示例。
1383

被折叠的 条评论
为什么被折叠?



