[concurrency-interest] Should CopyOnWriteArrayList implement RandomAccess?

Martin Buchholz martinrb at google.com
Wed Jun 26 15:33:42 EDT 2013

I agree that the original decision to have COWAL implement RandomAccess was
a (very small) mistake, but it's too late to fix now.

In any case, "concurrent list" is a bit of an oxymoron.

On Wed, Jun 26, 2013 at 3:55 AM, Nitsan Wakart <nitsanw at yahoo.com> wrote:

> Hi,
> Given the the javadoc for RandomAccess suggests that:
> "As a rule of thumb, a List implementation should implement this interface
> if, for typical instances of the class, this loop:
> for (int i=0, n=list.size(); i < n; i++) list.get(i);
> runs faster than this loop:
> for (Iterator i=list.iterator(); i.hasNext(); ) i.next();"
> But the above is not true for CopyOnWriteArrayList where the iterator
> performs better as the volatile read of the array is avoided on each entry
> and where the first loop is incorrect in any case(can lead to index out of
> bounds).
> Is that a bug or am I missing something here?
> Thanks,
> Nitsan
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20130626/c4293a7c/attachment.html>

More information about the Concurrency-interest mailing list