commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Muller <>
Subject Re: [JCS] ConcurrentModificationException
Date Wed, 25 Jan 2012 12:26:47 GMT

I don't know JCS at all, but the exception you get is the result of one 
thread updating a collection (in your case a HashMap) whilst another 
thread is iterating it. This would happen even if the Map was decorated 
using the Collections.synchronizedMap( myMap ) facility. To allow /true/ 
concurrent access/updates to a Map, the 
java.util.concurrent.ConcurrentHashMap (or another class implementing 
the ConcurrentMap) must be deployed.

If you use a synchronized Map as underlying structure for something, 
then you have to protect an iteration using the map itself as a 
synchronization token.

public class Users {

    private final Map< String, User > users = 
Collections.synchronizedMap( new HashMap< String, User >() );

    public void insertUser( User u ) {
       Require.notNull( u );
       users.put( u.getName(), u);

    public Collection< User > findUsersBornBefore( Date date ) {
        List< User > result = new ArrayList< User >();
        synchronized( users ) { // if not synchronized, the users 
structure may be concurrently modified
            for( User user : users.values() ) {
                if( user.getBirthdate().before( date ) ) {
                     result.add( user );
        return result;


May there is a way you can force JCS to use another Map implementation 
than HashMap? Some factory method somewhere?



On 25/01/2012 12:03, NM, Vijayakumar wrote:
> Hi All,
> We have an application which uses JCS cache to write data into IndexedDiskCache, sometime
are getting ConcurrentModificationException when application tries to update the cache object
frequently, please let me know what could be the reason and is there any workarounds to solve
the issue. We are using JCS 1.3
> 2012-01-25 10:38:44,088 ERROR [RemoteCache] -<Disabling remote cache due to error:
Failed to put [TEMP1] to tempRegion>
> java.util.ConcurrentModificationException
>                  at java.util.HashMap$HashIterator.nextEntry(
>                  at java.util.HashMap$
>                  at java.util.HashMap$
>                  at java.util.HashMap.writeObject(
>                  at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
>                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(
>                  at java.lang.reflect.Method.invoke(
>                  at
>                  at
>                  at
>                  at
>                  at
>                  at
>                  at
>                  at
>                  at
>                  at org.apache.jcs.utils.serialization.StandardSerializer.serialize(
>                  at org.apache.jcs.utils.serialization.SerializationConversionUtil.getSerializedCacheElement(
>                  at org.apache.jcs.auxiliary.remote.RemoteCache.update(
>                  at org.apache.jcs.engine.CacheAdaptor.handlePut(
>                  at org.apache.jcs.engine.PooledCacheEventQueue$PutEvent.doRun(
>                  at org.apache.jcs.engine.PooledCacheEventQueue$
>                  at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$
>                  at
> Regards,
> Vijay
> This message contains information that may be privileged or confidential and is the property
of the Capgemini Group. It is
> intended only for the person to whom it is addressed. If you are not the intended recipient,
you are not authorized to
> read, print, retain, copy, disseminate, distribute, or use this message or any part thereof.
If you receive this message
> in error, please notify the sender immediately and delete all copies of this message.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message