[concurrency-interest] ArrayBlockingQueue and addAll()
kav at it.edu
Thu Oct 19 14:16:53 EDT 2006
Doug Lea wrote:
> Kasper Nielsen wrote:
>> Any reason for not letting ArrayBlockingQueue.addAll() use a more
>> efficient implementation then the one inherited from AbstractCollection?
> It is mainly because there's not a huge possibility for improvement.
> Suppose for example a queue with capacity 100 gets calls from two different
> threads to addAll with 200 elements each. At best you could put in the
> first 100 for the first one, and let the others contend one-by-one as
> consumers remove elements.
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.
So what would happen would be
T1 : inserts 100 elements and throws IllegalStateException("Queue full");
T2 : throws IllegalStateException("Queue full");
More information about the Concurrency-interest