[concurrency-interest] Asynchronous-nature of ConcurrentLinkedQueue

Doug Lea dl at cs.oswego.edu
Thu May 20 08:44:14 EDT 2010

On 05/20/10 08:09, Vincent Gramoli wrote:
> Wouldn't it be clearer to add to the ConcurrentLinkedQueue.size() doc the
> sentence "Additionally, it is possible for the size to change during
> execution of this method, in which case the returned result will be
> inaccurate. Thus, this method is typically not very useful in concurrent
> applications." taken from ConcurrentSkipListMap.size().

This is a good idea; thanks.

It would be almost equally good to throw some exception if
concurrent data structures were not quiescent when computing size
(BTW, AbstractCollection does this for implementations
that do not override size()). But we decided that providing
SOME answer was a better policy, so that the method is
useful for occasional monitoring purposes and the like.

Also BTW, there have been a few papers on getting accurate
size snapshots for such structures, including one in DISC
last year (see http://www.cs.tau.ac.il/research/moran.tzafrir/).
But none of them seem to be plausible candidates for inclusion
because they add overhead to other methods as well. As David Holmes
mentioned, we don't want to penalize all users of an implementation
for the sake of those very few (perhaps no one!) who truly
need an accurate snapshot value.


More information about the Concurrency-interest mailing list