Concurreny problem in ConcurrentHashMap, ArralList

Hello,

I have the following datastructure

ConcurrentHashMap<String, List><Long>>

This is shared between multiple threads.

The values in the List<Long> is added/removed

via an iterator in one of the threads.

And the same List<Long> is added/sorted in another thread.

I am having a concurrentModificationException thrown

because of this.

I cannot use a CopyOnWriteArrayList since I need to

remove, set, and add elements via iterator and this will

throw an UnsupportedOperationException.

Is a ConcurrentLinkedQueue a better option?

[637 byte] By [angeshwara] at [2007-11-27 7:28:35]
# 1
By any means, your List<Long> must be a synchronized one. If the accessors should do wait/notify interaction over data availability, one defined in java.util.concurrent package could be usable.
hiwaa at 2007-7-12 19:08:43 > top of Java-index,Java Essentials,Java Programming...
# 2

From the API on ConcurrentHashMap:

"Retrieval operations (including get) generally do not block, so may overlap with update operations (including put and remove). Retrievals reflect the results of the most recently completed update operations holding upon their onset"

So there is no synchronizing on the List once it has been got from the map.

Try making the Lists in the map thread safe as well, e.g.Collections.synchronizedList(list)

dwga at 2007-7-12 19:08:43 > top of Java-index,Java Essentials,Java Programming...
# 3

> By any means, your List<Long> must be a synchronized

> one. If the accessors should do wait/notify

> interaction over data availability, one defined in

> java.util.concurrent package could be usable.

I dont have a wait/notify mechanism. All the methods accessed by the threads are synchronized. Is that not enough? for concurrent access?

angeshwara at 2007-7-12 19:08:43 > top of Java-index,Java Essentials,Java Programming...