Code example for PriorityBlockingQueue

Methods: isEmpty, peek, poll

0
   * Indicates whether a not a new result is available. 
   * 
   * @return true if a new result is available, false otherwise. 
   */ 
  public boolean hasNext() { 
    if (outputQueue.isEmpty()) {
      return false; 
    } else { 
      // Only return true if the top of the queue is the next item in the sequence 
      int nextId = outputQueue.peek().getId();
      return nextId == lastReturnedId + 1;
    } 
  } 
 
  /** 
   * Returns the next available result. 
   * 
   * @return 
   */ 
  public O next() { 
    if (!hasNext()) return null; 
    lastReturnedId++;
    QueueItem<O> result = outputQueue.poll();
    return result.getItem();
  } 
 
  /** 
   * Internal class for adding a job to the thread pool.