[concurrency-interest] CopyOnWriteArrayList.setAll?

Jed Wesley-Smith jed at atlassian.com
Thu Apr 23 18:21:55 EDT 2009


Interesting. In the Java5 version the modifications are protected by  
COWArrayList's monitor - synchronized(this) - so you simply need to  
acquire that object's monitor - synchronized(cowList) and and  call  
clear(), addAll().

In later versions however it has been changed to use a private  
ReentrantLock - so that approach will break. There doesn't appear to  
be any way to access that lock externally or from a sub-class.

Perhaps Doug can explain why this backwards incompatible change was  
made?

cheers,
jed.

On 24/04/2009, at 7:45 AM, Sam Berlin wrote:

> Hi Folks,
>
> Is there a way to emulate a CoW "set all" with  
> CopyOnWriteArrayList?  The goal is to make it impossible for someone  
> to view the list in a state except for where all the new items are  
> added and all the old ones are removed.
>
> It doesn't seem like it's possible (without restoring to blocking &  
> copying the data within the locks), but I may be missing something.   
> If I'm not missing something, would setAll be a good candidate for  
> inclusion into CoWArrayList?
>
> Sam
> _______________________________________________
> 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