PriorityBlockingQueue Class

Definition

An unbounded BlockingQueue blocking queue that uses the same ordering rules as class PriorityQueue and supplies blocking retrieval operations.

[Android.Runtime.Register("java/util/concurrent/PriorityBlockingQueue", DoNotGenerateAcw=true)]
[Java.Interop.JavaTypeParameters(new System.String[] { "E" })]
public class PriorityBlockingQueue : Java.Util.AbstractQueue, IDisposable, Java.Interop.IJavaPeerable, Java.IO.ISerializable, Java.Util.Concurrent.IBlockingQueue
[<Android.Runtime.Register("java/util/concurrent/PriorityBlockingQueue", DoNotGenerateAcw=true)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "E" })>]
type PriorityBlockingQueue = class
    inherit AbstractQueue
    interface ISerializable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
    interface IBlockingQueue
    interface IQueue
    interface ICollection
    interface IIterable
Inheritance
Attributes
Implements

Remarks

An unbounded BlockingQueue blocking queue that uses the same ordering rules as class PriorityQueue and supplies blocking retrieval operations. While this queue is logically unbounded, attempted additions may fail due to resource exhaustion (causing OutOfMemoryError). This class does not permit null elements. A priority queue relying on Comparable natural ordering also does not permit insertion of non-comparable objects (doing so results in ClassCastException).

This class and its iterator implement all of the <em>optional</em> methods of the Collection and Iterator interfaces. The Iterator provided in method #iterator() and the Spliterator provided in method #spliterator() are <em>not</em> guaranteed to traverse the elements of the PriorityBlockingQueue in any particular order. If you need ordered traversal, consider using Arrays.sort(pq.toArray()). Also, method drainTo can be used to <em>remove</em> some or all elements in priority order and place them in another collection.

Operations on this class make no guarantees about the ordering of elements with equal priority. If you need to enforce an ordering, you can define custom classes or comparators that use a secondary key to break ties in primary priority values. For example, here is a class that applies first-in-first-out tie-breaking to comparable elements. To use it, you would insert a new FIFOEntry(anEntry) instead of a plain entry object.

{@code
            class FIFOEntry<E extends Comparable<? super E>>
                implements Comparable<FIFOEntry<E>> {
              static final AtomicLong seq = new AtomicLong();
              final long seqNum;
              final E entry;
              public FIFOEntry(E entry) {
                seqNum = seq.getAndIncrement();
                this.entry = entry;
              }
              public E getEntry() { return entry; }
              public int compareTo(FIFOEntry<E> other) {
                int res = entry.compareTo(other.entry);
                if (res == 0 && other.entry != this.entry)
                  res = (seqNum < other.seqNum ? -1 : 1);
                return res;
              }
            }}

This class is a member of the Java Collections Framework.

Added in 1.5.

Java documentation for java.util.concurrent.PriorityBlockingQueue.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

PriorityBlockingQueue()

Creates a PriorityBlockingQueue with the default initial capacity (11) that orders its elements according to their Comparable natural ordering.

PriorityBlockingQueue(ICollection)

Creates a PriorityBlockingQueue containing the elements in the specified collection.

PriorityBlockingQueue(Int32, IComparator)

Creates a PriorityBlockingQueue with the specified initial capacity that orders its elements according to the specified comparator.

PriorityBlockingQueue(Int32)

Creates a PriorityBlockingQueue with the specified initial capacity that orders its elements according to their Comparable natural ordering.

PriorityBlockingQueue(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsEmpty

To be added

(Inherited from AbstractCollection)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Add(Object)

To be added

(Inherited from AbstractCollection)
AddAll(ICollection)

To be added

(Inherited from AbstractCollection)
Clear()

To be added

(Inherited from AbstractCollection)
Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Comparator()

Returns the comparator used to order the elements in this queue, or null if this queue uses the Comparable natural ordering of its elements.

Contains(Object)

To be added

(Inherited from AbstractCollection)
ContainsAll(ICollection)

To be added

(Inherited from AbstractCollection)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
DrainTo(ICollection, Int32)
DrainTo(ICollection)
Element()

Retrieves, but does not remove, the head of this queue.

(Inherited from AbstractQueue)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
ForEach(IConsumer)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
Iterator()

Returns an iterator over the elements in this queue.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
Offer(Object, Int64, TimeUnit)

Inserts the specified element into this priority queue.

Offer(Object)

Inserts the specified element into this priority queue.

Peek()

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

Poll()

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Poll(Int64, TimeUnit)

Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.

Put(Object)

Inserts the specified element into this priority queue.

RemainingCapacity()

Always returns Integer.MAX_VALUE because a PriorityBlockingQueue is not capacity constrained.

Remove()

Retrieves and removes the head of this queue.

(Inherited from AbstractQueue)
Remove(Object)

To be added

(Inherited from AbstractCollection)
RemoveAll(ICollection)

To be added

(Inherited from AbstractCollection)
RemoveIf(IPredicate)
RetainAll(ICollection)

To be added

(Inherited from AbstractCollection)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
Size()

Returns a count of how many objects this Collection contains.

Spliterator()

Returns a Spliterator over the elements in this queue.

Take()

Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.

ToArray()

To be added

(Inherited from AbstractCollection)
ToArray(Object[])

To be added

(Inherited from AbstractCollection)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)
OfferAsync(IBlockingQueue, Object, Int64, TimeUnit)
OfferAsync(IBlockingQueue, Object)
PollAsync(IBlockingQueue, Int64, TimeUnit)
PutAsync(IBlockingQueue, Object)
TakeAsync(IBlockingQueue)
ToEnumerable(IIterable)
ToEnumerable<T>(IIterable)

Applies to