您的位置:首页 > 产品设计 > UI/UE

PriorityBlockingQueue

2016-11-01 23:42 190 查看
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 the
java.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 
Comparable
implementation.

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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java concurrent