[concurrency-interest] COWList snapshot.

Jason Mehrens jason_mehrens at hotmail.com
Mon Feb 24 10:30:39 EST 2014

Arrays.asImmutableList that seems like the way to go about doing this.
My understanding is that COWIterator is a read-only and therefore would have been acceptable for use in the previous case.
new CopyOnWriteArrayList().iterator().remove();
Exception in thread "main" java.lang.UnsupportedOperationException
 at java.util.concurrent.CopyOnWriteArrayList$COWIterator.remove(CopyOnWriteArrayList.java:1040)

Might be worth adding Arrays.asImmutableListIterator which would allow the removal of the COWIterator class.

> Date: Fri, 21 Feb 2014 15:55:59 -0800 
> Subject: Re: [concurrency-interest] COWList snapshot. 
> From: martinrb at google.com 
> To: jason_mehrens at hotmail.com 
> CC: concurrency-interest at cs.oswego.edu 
> On Fri, Feb 21, 2014 at 3:17 PM, Jason Mehrens 
> <jason_mehrens at hotmail.com<mailto:jason_mehrens at hotmail.com>> wrote: 
> Martin, 
> Looks correct. Since the snapshot can't change I assume it should 
> implement RandomAccess? Maybe override iterator() and listIterator() to 
> return COWIterator for fun and profit? 
> Immutable List iterator is much simpler. 
> As Henri pointed out, you can use 
> Collections.unmodifiableList(Arrays.asList(getArray())). Arrays.asList 
> doesn't perform any safe coping of the input array. 
> Ohhh, light bulb just lit up.... ding ding ding ... Yeah, that does 
> indeed look very simple... 
> Back to the drawing board. We add the much more fundamental 
> Arrays.asImmutableList(T...) that everyone has been asking for 
> elsewhere, and then 
> COWAList.snapshot can return Arrays.asImmutableList(getArray()) 

More information about the Concurrency-interest mailing list