[concurrency-interest] New method for BlockingQueue

Joe Bowbeer jozart@blarg.net
Thu, 28 Oct 2004 21:37:35 -0700

Jean Morissette writes:

> I would like [...] drainTo(Collection c, long timeout, TimeUnit unit).

A two-part strategy comes to mind:

1. Poll for the first element initially, with specified timeout.
2. Then fetch any remaining elements with drainTo -- or poll with timeout=0 
while there are more elements.

Does this suffice?  Is it inefficient?

----- Original Message ----- 
From: "Jean Morissette" <jean.morissette666@videotron.ca>
To: <concurrency-interest@altair.cs.oswego.edu>
Sent: Thursday, October 28, 2004 9:08 PM
Subject: [concurrency-interest] New method for BlockingQueue

I would like to use a method in BlockingQueue that blocks on the queue
up until a timeout occurs or until an element appears on the queue,
returning all elements waiting on the queue at that time.

It's a little bit like a mix of methods poll(long timeout, TimeUnit
unit) and drainTo(Collection c), thus something like drainTo(Collection
c, long timeout, TimeUnit unit).

I don't think that there is a way to implements efficiently this method
by wrapping a BlockingQueue.  Am-I wrong?

Is it possible that this method could be added in a future release?