[concurrency-interest] Method on LinkedBlockingQueue throws IllegalStateException

Szabolcs Ferenczi szabolcs.ferenczi at gmail.com
Tue Apr 17 16:34:42 EDT 2007


There is a method defined on LBQ (well already on AbstractQueue)
that throws IllegalStateException. The LinkedBlockingQueue.add method
throws an IllegalStateException when the queue is at the max capacity
(full) at the time the method is called. It is strange, isn't it? But
it is true.

I believe an operation on a queue being full is not illegal in a multi-threaded
environment. It just happens sometimes at non deterministic moments.

I think, throwing the exception might be justified on a data structure, which is
designed to be used in a single threaded environment but it is a
completely mistaken behavior on a shared data structure. I hope the
reason why is obvious to anyone who works with multiple threads.

 I think this method and related ones such as the method remove (throws
NoSuchElementException) should be fixed in forthcoming releases,
if methods like these are needed at all.

Any comment?

Best Regards,
Szabolcs


More information about the Concurrency-interest mailing list