[concurrency-interest] BlockingQueue or Queue / peek()

Johannes.Lichtenberger Johannes.Lichtenberger at uni-konstanz.de
Thu Feb 2 14:19:08 EST 2012


On 02/02/2012 07:41 PM, Johannes.Lichtenberger wrote:
> Hello,
> 
> why doesn't the BlockingQueue interface contain a method similar to
> 
> public E poll(long timeout, TimeUnit unit) throws InterruptedException;?
> 
> I think it would be great to allow waiting a specified time if nothing
> is in the Queue. In some circumstances I'd like to peek() a
> Future-instance instead of using take() or poll(long, TimeUnit) but it's
> necessary to wait if at the time calling the method nothing is in the queue.
> 
> Perhaps I missed something? ;-)
> 
> Ok, seems peek() is defined in the Queue-interface together with an
> element()-method. Do I have to catch the NoSuchElementException and loop
> and sleep() until something is available and to give up after some time
> period or do I really miss something?

Or maybe "pulling" the top element and push it back, but hm.

kind regards,
Johannes


More information about the Concurrency-interest mailing list