35
36 package java.util.concurrent;
37
38 import java.lang.invoke.MethodHandles;
39 import java.lang.invoke.VarHandle;
40 import java.util.AbstractQueue;
41 import java.util.Arrays;
42 import java.util.Collection;
43 import java.util.Comparator;
44 import java.util.Iterator;
45 import java.util.NoSuchElementException;
46 import java.util.Objects;
47 import java.util.PriorityQueue;
48 import java.util.Queue;
49 import java.util.SortedSet;
50 import java.util.Spliterator;
51 import java.util.concurrent.locks.Condition;
52 import java.util.concurrent.locks.ReentrantLock;
53 import java.util.function.Consumer;
54 import java.util.function.Predicate;
55 import jdk.internal.misc.SharedSecrets;
56
57 /**
58 * An unbounded {@linkplain BlockingQueue blocking queue} that uses
59 * the same ordering rules as class {@link PriorityQueue} and supplies
60 * blocking retrieval operations. While this queue is logically
61 * unbounded, attempted additions may fail due to resource exhaustion
62 * (causing {@code OutOfMemoryError}). This class does not permit
63 * {@code null} elements. A priority queue relying on {@linkplain
64 * Comparable natural ordering} also does not permit insertion of
65 * non-comparable objects (doing so results in
66 * {@code ClassCastException}).
67 *
68 * <p>This class and its iterator implement all of the <em>optional</em>
69 * methods of the {@link Collection} and {@link Iterator} interfaces.
70 * The Iterator provided in method {@link #iterator()} and the
71 * Spliterator provided in method {@link #spliterator()} are <em>not</em>
72 * guaranteed to traverse the elements of the PriorityBlockingQueue in
73 * any particular order. If you need ordered traversal, consider using
74 * {@code Arrays.sort(pq.toArray())}. Also, method {@code drainTo} can
75 * be used to <em>remove</em> some or all elements in priority order and
|
35
36 package java.util.concurrent;
37
38 import java.lang.invoke.MethodHandles;
39 import java.lang.invoke.VarHandle;
40 import java.util.AbstractQueue;
41 import java.util.Arrays;
42 import java.util.Collection;
43 import java.util.Comparator;
44 import java.util.Iterator;
45 import java.util.NoSuchElementException;
46 import java.util.Objects;
47 import java.util.PriorityQueue;
48 import java.util.Queue;
49 import java.util.SortedSet;
50 import java.util.Spliterator;
51 import java.util.concurrent.locks.Condition;
52 import java.util.concurrent.locks.ReentrantLock;
53 import java.util.function.Consumer;
54 import java.util.function.Predicate;
55 import jdk.internal.access.SharedSecrets;
56
57 /**
58 * An unbounded {@linkplain BlockingQueue blocking queue} that uses
59 * the same ordering rules as class {@link PriorityQueue} and supplies
60 * blocking retrieval operations. While this queue is logically
61 * unbounded, attempted additions may fail due to resource exhaustion
62 * (causing {@code OutOfMemoryError}). This class does not permit
63 * {@code null} elements. A priority queue relying on {@linkplain
64 * Comparable natural ordering} also does not permit insertion of
65 * non-comparable objects (doing so results in
66 * {@code ClassCastException}).
67 *
68 * <p>This class and its iterator implement all of the <em>optional</em>
69 * methods of the {@link Collection} and {@link Iterator} interfaces.
70 * The Iterator provided in method {@link #iterator()} and the
71 * Spliterator provided in method {@link #spliterator()} are <em>not</em>
72 * guaranteed to traverse the elements of the PriorityBlockingQueue in
73 * any particular order. If you need ordered traversal, consider using
74 * {@code Arrays.sort(pq.toArray())}. Also, method {@code drainTo} can
75 * be used to <em>remove</em> some or all elements in priority order and
|