< prev index next >

src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java

Print this page




  84  * <pre> {@code
  85  * class FIFOEntry<E extends Comparable<? super E>>
  86  *     implements Comparable<FIFOEntry<E>> {
  87  *   static final AtomicLong seq = new AtomicLong(0);
  88  *   final long seqNum;
  89  *   final E entry;
  90  *   public FIFOEntry(E entry) {
  91  *     seqNum = seq.getAndIncrement();
  92  *     this.entry = entry;
  93  *   }
  94  *   public E getEntry() { return entry; }
  95  *   public int compareTo(FIFOEntry<E> other) {
  96  *     int res = entry.compareTo(other.entry);
  97  *     if (res == 0 && other.entry != this.entry)
  98  *       res = (seqNum < other.seqNum ? -1 : 1);
  99  *     return res;
 100  *   }
 101  * }}</pre>
 102  *
 103  * <p>This class is a member of the
 104  * <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework">
 105  * Java Collections Framework</a>.
 106  *
 107  * @since 1.5
 108  * @author Doug Lea
 109  * @param <E> the type of elements held in this queue
 110  */
 111 @SuppressWarnings("unchecked")
 112 public class PriorityBlockingQueue<E> extends AbstractQueue<E>
 113     implements BlockingQueue<E>, java.io.Serializable {
 114     private static final long serialVersionUID = 5595510919245408276L;
 115 
 116     /*
 117      * The implementation uses an array-based binary heap, with public
 118      * operations protected with a single lock. However, allocation
 119      * during resizing uses a simple spinlock (used only while not
 120      * holding main lock) in order to allow takes to operate
 121      * concurrently with allocation.  This avoids repeated
 122      * postponement of waiting consumers and consequent element
 123      * build-up. The need to back away from lock during allocation
 124      * makes it impossible to simply wrap delegated




  84  * <pre> {@code
  85  * class FIFOEntry<E extends Comparable<? super E>>
  86  *     implements Comparable<FIFOEntry<E>> {
  87  *   static final AtomicLong seq = new AtomicLong(0);
  88  *   final long seqNum;
  89  *   final E entry;
  90  *   public FIFOEntry(E entry) {
  91  *     seqNum = seq.getAndIncrement();
  92  *     this.entry = entry;
  93  *   }
  94  *   public E getEntry() { return entry; }
  95  *   public int compareTo(FIFOEntry<E> other) {
  96  *     int res = entry.compareTo(other.entry);
  97  *     if (res == 0 && other.entry != this.entry)
  98  *       res = (seqNum < other.seqNum ? -1 : 1);
  99  *     return res;
 100  *   }
 101  * }}</pre>
 102  *
 103  * <p>This class is a member of the
 104  * <a href="{@docRoot}/java.base/java/util/package-summary.html#CollectionsFramework">
 105  * Java Collections Framework</a>.
 106  *
 107  * @since 1.5
 108  * @author Doug Lea
 109  * @param <E> the type of elements held in this queue
 110  */
 111 @SuppressWarnings("unchecked")
 112 public class PriorityBlockingQueue<E> extends AbstractQueue<E>
 113     implements BlockingQueue<E>, java.io.Serializable {
 114     private static final long serialVersionUID = 5595510919245408276L;
 115 
 116     /*
 117      * The implementation uses an array-based binary heap, with public
 118      * operations protected with a single lock. However, allocation
 119      * during resizing uses a simple spinlock (used only while not
 120      * holding main lock) in order to allow takes to operate
 121      * concurrently with allocation.  This avoids repeated
 122      * postponement of waiting consumers and consequent element
 123      * build-up. The need to back away from lock during allocation
 124      * makes it impossible to simply wrap delegated


< prev index next >