title: java BlockingQueue does not have a blocking peek?
body: <p>I have a blocking queue of objects.</p>
  
  <p>I want to write a thread that blocks till there is a object on the queue. Similar to the functionality provided by BlockingQueue.take().</p>
  
  <p>However, since I do not know if I will be able to process the object successfully, I want to just peek() and not remove the object. I want to remove the object only if I am able to process it successfully.</p>
  
  <p>So, I would like a blocking peek() function. Currently, peek() just returns if the queue is empty as per the javadocs.</p>
  
  <p>Am I missing something? Is there another way to achieve this functionality?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Any thoughts on if I just used a thread safe queue and peeked and slept instead? </p>
  
  <pre><code>public void run() {
      while (!exit) {
          while (queue.size() != 0) {
              Object o =  queue.peek();
              if (o != null) {
                  if (consume(o) == true) {
                      queue.remove();
                  } else {
                      Thread.sleep(10000); //need to backoff (60s) and try again
                  }
              }
          }
          Thread.sleep(1000); //wait 1s for object on queue
      }
  }
  </code></pre>
  
  <p>Note that I only have one consumer thread and one (separate) producer thread. I guess this isn't as efficient as using a BlockingQueue... Any comments appreciated.</p>