[concurrency-interest] COWList snapshot.

Zhong Yu zhong.j.yu at gmail.com
Wed Feb 19 15:08:35 EST 2014


On Wed, Feb 19, 2014 at 1:55 PM, Martin Buchholz <martinrb at google.com> wrote:
> Владимир,
>
> I agree that a snapshot method as you propose would be useful.  As always,
> implementing the List interface ends up being rather a lot of tedious work,
> which may be a reason it never got done.

Interestingly, JDK doesn't not seem to have a method to wrap an array
as a read-only list. A lot of people use Arrays.asList(), which is
wrong...

Zhong Yu

>
>
> On Wed, Feb 19, 2014 at 10:41 AM, Владимир Озеров <ppozerov at gmail.com>
> wrote:
>>
>> Jason,
>>
>> The main problem with copying constructor is volatile access to array
>> which is expected to be immutable. Furthermore COWList created from another
>> COWList breaks snapshot semantics - it can be changed. The same applies for
>> clone().
>> Proposed wrapper should be pretty similar to COWIterator - thin wrapper
>> with final array.reference inside. Old thread with example of this approach
>> - http://cs.oswego.edu/pipermail/concurrency-interest/2009-March/005926.html
>>
>> Vladimir.
>>
>>
>> 2014-02-19 19:12 GMT+04:00 Jason Mehrens <jason_mehrens at hotmail.com>:
>>
>>> Vladimir,
>>>
>>> You can use the COWAL copy constructor which has a fast path for COWAL or
>>> use the clone method.
>>>
>>> Jason
>>>
>>> ________________________________
>>> > Date: Wed, 19 Feb 2014 18:21:14 +0400
>>> > From: ppozerov at gmail.com
>>> > To: concurrency-interest at cs.oswego.edu
>>> > Subject: [concurrency-interest] COWList snapshot.
>>> >
>>> > Hi,
>>> >
>>> > I was a little bit suprized when found that there is no convenient way
>>> > to get snapshot of COW list.
>>> > .
>>> > What I need is to get snapshot of the list (in form of either array or
>>> > List, doesn't matter) and perform several reads on it (index lookups or
>>> > traversals). For this reason I cannot use iterator. Also I would like
>>> > to avoid unnecessary array copying since I'm not going to perform
>>> > writes. So getting internal array appears to be the best way to do that
>>> > from performance perspective. Copying constructor and forEach() method
>>> > already employ this technique in JDK8
>>> >
>>> > (http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/main/java/util/concurrent/CopyOnWriteArrayList.java?view=markup)
>>> >
>>> > For now there is no way to get that array since all access to it are
>>> > either private or package-scoped. Could something like "List<T>
>>> > snapshot()" be added to COWList API returning unmodifiable wrapper over
>>> > internal array? Or at least getArray() could be made protected so that
>>> > developers can use it on their own risk :-)
>>> >
>>> > Vladimir.
>>> >
>>> > _______________________________________________ Concurrency-interest
>>> > mailing list Concurrency-interest at cs.oswego.edu
>>> > http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>>
>>
>>
>> _______________________________________________
>> Concurrency-interest mailing list
>> Concurrency-interest at cs.oswego.edu
>> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>>
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>



More information about the Concurrency-interest mailing list