[concurrency-interest] Should CopyOnWriteArrayList implement RandomAccess?

Scott Blum dragonsinth at gmail.com
Wed Jun 26 13:55:40 EDT 2013


Seems like a nit to me.  You can still do random lookup in constant time.
On Jun 26, 2013 3:58 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/af2375c0/attachment-0001.html>


More information about the Concurrency-interest mailing list