Re: [javagroups-users] ReplicatedHashMap question
Brought to you by:
belaban
From: Bela B. <be...@ya...> - 2007-08-21 07:29:17
|
Ahrens, Richard (Equity Linked Technology) wrote: > Since ReplicatedHashMap in jgroups-2.5.0 extends HashMap and none of > its methods are synchronized, is there a way to prevent a > ConcurrentModificationException if the application code is reading or > writing to the map at the same time a JGroups thread is invoking > _put(), _remove(), etc.? No, not by default. ReplicatedHashMap has the same semantics as HashMap, which is unsynchronized. However, since RHM delegates all calls to its super class, you could do ReplicatedHashMap rhm=...; Map map=Collections.synchronizedMap(rhm); and access the RHM only through 'map'. This should work, as even replicator methods such as _put(), _clear() etc delegate to HashMap's put(), clear() and so on, and these will be synchronized. Note that ReplicatedHashMap is quite simple with respect to functionality. If you want locking, cache loading etc, I recommend JBossCache. Cheers, -- Bela Ban Lead JGroups / JBoss Clustering team JBoss - a division of Red Hat |