logo       

Re: ArrayBlockingQueue and addAll(): msg#00038

java.jsr.166-concurrency

Subject: Re: ArrayBlockingQueue and addAll()


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?
>>
>
> 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");

- Kasper


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise