[concurrency-interest] CopyOnWrite for Maps and other lists (not just ArrayList)

Morgan Conrad morganconrad at yahoo.com
Fri Dec 3 18:56:08 EST 2010


Our project was throwing intermittent ConcurrentModificationExceptions because of the classic bug, one thread iterating over a collection while another was modifying it.  Most of the bugs were solved by changing to a CopyOnWriteArrayList - a wonderful class, thank you!

But, in a few cases, the underlying list behavior we wanted was NOT ArrayList, (there was a sorted list) or, the offending collection was a Map.  Rather than writing multiple classes CopyOnWriteThis, CopyOnWriteThat, I came up with the idea of writing wrapper classes, much like Collections.SynchronizedMap, to provide "copy-on" behavior for the underlying collection.  It took quite a while, and, it turns out we fixed the problems in other ways so the code was never really used.

I did some Googling, and searching of this mailing list, and didn't find anything similar.  Is this "copy-on-wrapper" idea a useful concept?  If so, I'd be happy to provide the code and my blog link where I talk about it.  Comments and feedback would be welcome, as I imagine there could be issues or improvements.


Sincerely,
Morgan Conrad




      


More information about the Concurrency-interest mailing list