[concurrency-interest] BlockingQueue or Queue / peek()
yshavit at akiban.com
Thu Feb 2 15:41:56 EST 2012
I may be missing something in your question, but it seems to me that
BlockingQueue does contain a method similar to the method you're asking
for. In fact, it's exactly what you're looking for. Same name, same inputs,
same output, same exception.
On Thu, Feb 2, 2012 at 2:29 PM, Johannes.Lichtenberger <
Johannes.Lichtenberger at uni-konstanz.de> wrote:
> On 02/02/2012 08:19 PM, Johannes.Lichtenberger wrote:
> > 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
> >> 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.
> Which certainly would involve some form of external synchronization such
> that the producers can't add something in the meanwhile, not really
> appropriate I think ;-)
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest