[concurrency-interest] New method for BlockingQueue

David Holmes dholmes@dltech.com.au
Fri, 29 Oct 2004 14:47:35 +1000

Hello Jean,

> 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.

In the absence of atomic bulk operations (like addAll) I'm not sure you
could ever expect to drain more than one element from the queue. Scheduling
issues aside, as soon as one element is added then you would drain it.

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

No you are not wrong. These sort of arbitrary atomic sequences require
additional locking to coordinate all the methods involved. You would have to
wrap to provide a fully synchronized version that added the atomic method(s)
you require.

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

Without additional semantics for bulk operations - which themselves imply
the need for total locking - such an operation makes little sense. You'd end
up needing to be fully synchronized to make this work - as far as I can see
at present.

David Holmes