[concurrency-interest] LinkedBlockingQueue does not throwNullPointerException for the method call contains

David Holmes dcholmes at optusnet.com.au
Sun Apr 15 20:33:01 EDT 2007

> I am curious when a query such as "contains(youCanHaveThisItem)" is
> useful in a concurrent context. Remember---in a concurrent context. It
> may be useful in a single threaded environment where it is guarantied
> that the subsequent get will find it there but you can do nothing with
> this query in a multi-threaded case, do you?

If your requirement is "contains(X) implies get(X) will succeed" - then no
you can't in general do that. But queries aren't always used that way - it
may be a "hint" to decide whether to add something or not; it may be a
simple "sample" to see how often, in general, a type of item exists in the
structure. Also just because a data structure is used concurrently it
doesn't mean that all operations are applied concurrently at all times - it
depends on how the data structure is used. For example, multiple producer
with single-consumer - the consumer can use contains(x) and know get(x) will
succeed. Or, after being concurrently populated the data structure may be
handed over to a single thread that performs some initial pre-processing,
perhaps removing certain items or doing an extra processing step for those
items, before handing of to more general "consumption" using multiple

I don't presume to know all the ways in which people use their data

David Holmes

More information about the Concurrency-interest mailing list