[concurrency-interest] COWList snapshot.

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


On Wed, Feb 19, 2014 at 12:41 PM, Владимир Озеров <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().

That doesn't matter, right? Any change to the copy/clone will not
affect the origin. If you must hand over the copy/clone to others as
read-only list, Collections.unmodifiableList() wrapper would work
(unless you don't like the extra overhead)

> 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
>



More information about the Concurrency-interest mailing list