[concurrency-interest] ArrayBlockingQueue and addAll()

Doug Lea dl at cs.oswego.edu
Thu Oct 19 15:47:36 EDT 2006


Kasper Nielsen wrote:
> 
> Doug Lea wrote:
>> Kasper Nielsen wrote:
>>> Hi,
>>>
>>> Any reason for not letting ArrayBlockingQueue.addAll() use a more 
>>> efficient implementation then the one inherited from AbstractCollection?
>>>
> I can't see how they can contend one-by-one, the contract of add is to 
> throw a RuntimeException() if any element cannot be added.

Yes; sorry. I was thinking about blocking cases. However, variants of
the same issue hold: Suppose that there is a very fast consumer that
removes elements as fast as they are added. In this case, adding
200 elements one-by-one in a 100-capacity queue may succeed, whereas
if 100 are put in, in bulk, and then an exception is thrown for
the rest, only 100 will be transferred. Of course, since there are
no promises about these things either way, this would be equally
legal. And sometimes faster in practice, so it is still a useful
suggestion.

-Doug




More information about the Concurrency-interest mailing list