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

Johannes.Lichtenberger Johannes.Lichtenberger at uni-konstanz.de
Thu Feb 2 13:41:08 EST 2012


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?

kind regards,

More information about the Concurrency-interest mailing list