[concurrency-interest] LinkedBlockingQueue does not throw NullPointerException for the method call contains
szabolcs.ferenczi at gmail.com
Sun Apr 15 19:34:03 EDT 2007
On 16/04/07, Joe Bowbeer <joe.bowbeer at gmail.com> wrote:
> I was misled by the 'contains' method documentation in the same way
> Szabolcs was, but I now see that the meaning of 'optional' is spelled
> out in the Collection javadoc.
> I think it would be nice if all AbstractQueue implementations
> implemented this optional exception in the same way, and maybe they do.
> In any event, it could do more harm than good to change it now, I realize.
I am afraid there is a major difference between a Collection which is
designed for use in a single threaded environment and a
(Linked)BlockingQueue which is a shared data structure intended to be
used by multiple threads. While throwing an exception can be justified
in a single threaded environment, it is not justified in case of
multiple threads using the shared data structure. In the latter case
it is not an exception when a queried piece of data is not present at
the time of query. Although, any query like this does not make too
much sense either, the documentation should be exact, however.
Besides, I see major problems with this method in case of a shared
data structure as well as with other methods that shared classes
inherit from sequential classes.
More information about the Concurrency-interest