[concurrency-interest] LinkedBlockingQueue does not throwNullPointerException for the method call contains
dcholmes at optusnet.com.au
Sun Apr 15 20:00:40 EDT 2007
Szabolcs Ferenczi wrote:
> 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.
I can't see what threading has to do with whether a method throws an
exception or not.
In the case of contains(null) it really boils down to whether asking for
something that can't possibly be there is a "silly question" that should
just be ignored (ie return false), or whether it indicates a serious flaw in
the caller because the caller should never have presented a null in the
first place - and so throw an Exception.
> 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.
Any query method has limits in a concurrent context. That doesn't mean they
aren't useful, it just means the limits have to be understood. Ultimately it
how an application uses the data structure that determines what makes sense
and what does not. The data structure provides an API that is as general as
possible to account for as many use-cases as is reasonable.
More information about the Concurrency-interest