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

Kasper Nielsen kasper at kav.dk
Wed Dec 8 16:22:29 EST 2010

On 08-12-2010 22:05, Morgan Conrad wrote:
> BTW, thanks everybody for the feedback!
> --- On Wed, 12/8/10, Kasper Nielsen<kasper at kav.dk>  wrote:
>>> My goals were decent speed, not ultimate speed.
>> May I ask you what use case you are trying to solve. I fail
>> to see what
>> kind of benefits your implementation provides over either
>> ConcurrentSkipListMap, ConcurrentHashMap or
>> Collections.synchronizedMap?
> We were working with old code written somewhere else and *way* before java.util.concurrent.  Instead of rewriting a lot of code to use (or subclass) ConcurrentSkipListMap, I thought a wrapper would be easier.  Also, I was very familiar with CopyOnWriteArrayList, and our maps fit the "write seldom, iterate often" model.  Since most of the issues showed up as ConcurrentModificationExceptions, part of the effort was really debugging/testing to verify where they were coming from.  In some ways, these classes are a "let's try this, if it fixes the CME we know the issue, and hopefully performance is still adequate".
> I'm less familiar with Concurrent maps.  I definitely did not want to be locked during iteration, because in our code that can be time consuming and affects the GUI.

I would definitly go with ConcurrentHashMap then, unless your data needs 
to sorted in which case you would choose ConcurrentSkipListMap.
They both provide fast concurrent iterators and neither throws 


More information about the Concurrency-interest mailing list