You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-users@jakarta.apache.org by Joshua Szmajda <jo...@loki.ws> on 2007/07/17 17:00:23 UTC

ConcurrentModificationException

Hey all,

I'm using JCS with a Remote Cache Server and a number of web servers. 
Now and then I'll get a ConcurrentModificationException as two of my 
servers attempt to update the same key in a particular region at the 
same time. Is there any good way to avoid this? Preferably I'd like each 
server to be able to update the cache, and use whichever is put in last 
as the 'real' version.

I was thinking I could use some sort of locking with each server having 
its own key to update, then before each update a server would check all 
servers' lock keys and only once they were all clear would it perform 
whatever update it was going to do. This seems really slow though, and I 
really need all the performance I can get.

Here's the stacktrace if it helps:

java.util.ConcurrentModificationException
        at java.util.ArrayList.writeObject(ArrayList.java:572)
        at sun.reflect.GeneratedMethodAccessor142.invoke(Unknown Source)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:917)
        at 
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1339)
        at 
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
        at 
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
        at 
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
        at 
org.apache.jcs.utils.serialization.StandardSerializer.serialize(StandardSerializer.java:50)
        at 
org.apache.jcs.utils.serialization.SerializationConversionUtil.getSerializedCacheElement(SerializationConversionUtil.java:73)
        at 
org.apache.jcs.auxiliary.remote.RemoteCache.update(RemoteCache.java:207)
        at 
org.apache.jcs.engine.CacheAdaptor.handlePut(CacheAdaptor.java:91)
        at 
org.apache.jcs.engine.CacheEventQueue$PutEvent.doRun(CacheEventQueue.java:688)
        at 
org.apache.jcs.engine.CacheEventQueue$AbstractCacheEvent.run(CacheEventQueue.java:607)
        at 
org.apache.jcs.engine.CacheEventQueue$QProcessor.run(CacheEventQueue.java:575)


Thanks!
-Josh

---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


Replication fails on modified objects

Posted by Michael Toback <Mi...@chordiant.com>.

Michael I Toback 
Principal Engineer
Orchestrating Business Processes
Chordiant Software
Cupertino, Ca 95014
(408)-517-6165


We are encountering a strange error with JCS. We have a workaround, but
still are puzzled by it.

We have a lateral cache with two instances. Sometimes when we modified
an object it gets propagated to the other caches, sometimes not.

Here is the scenario, using the above simple object:

1)       Put the Object in the cache with a key of "hello", and inside
the object have test string "I'm here"

2)       See the object get replicated to the other cache

3)       Get the object back from the cache and change the "testStr" in
it to "bye bye"

4)       Re-Put that object into the cache with the same Key

5)       The change to that object does not get replicated. Therefore,
the other server instance of the cache still has the older object
containing "I'm here"

Now modify step 3 by creating a new object and do a shallow clone of the
original object, and in step 4 put the new object in the cache instead.

Our engineering staff speculates that JCS uses "==" instead of ".equals"
to determine if the put changes the object.

Comments?

Michael
The information transmitted herewith is sensitive      information of Chordiant Software or its customers and is intended only for use to the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon, this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.


Re: ConcurrentModificationException

Posted by Joshua Szmajda <jo...@loki.ws>.
Ah yes, of course references. That makes complete sense. Thanks!

Aaron Smuts wrote:
> This exception is being thrown from your object.  You
> must have cached a collection, an array list.  Might
> you have been modifying the object at the same time. 
> remember, the cache holds references.  If you modify
> an array list while you are iterating over it, you can
> get a concurrent modification exception. 
>
> Aaron
>
>
> --- Joshua Szmajda <jo...@loki.ws> wrote:
>
>   
>> Hey all,
>>
>> I'm using JCS with a Remote Cache Server and a
>> number of web servers. 
>> Now and then I'll get a
>> ConcurrentModificationException as two of my 
>> servers attempt to update the same key in a
>> particular region at the 
>> same time. Is there any good way to avoid this?
>> Preferably I'd like each 
>> server to be able to update the cache, and use
>> whichever is put in last 
>> as the 'real' version.
>>
>> I was thinking I could use some sort of locking with
>> each server having 
>> its own key to update, then before each update a
>> server would check all 
>> servers' lock keys and only once they were all clear
>> would it perform 
>> whatever update it was going to do. This seems
>> really slow though, and I 
>> really need all the performance I can get.
>>
>> Here's the stacktrace if it helps:
>>
>> java.util.ConcurrentModificationException
>>         at
>> java.util.ArrayList.writeObject(ArrayList.java:572)
>>         at
>>
>>     
> sun.reflect.GeneratedMethodAccessor142.invoke(Unknown
>   
>> Source)
>>         at 
>>
>>     
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>   
>>         at
>> java.lang.reflect.Method.invoke(Method.java:585)
>>         at 
>>
>>     
> java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:917)
>   
>>         at 
>>
>>     
> java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1339)
>   
>>         at 
>>
>>     
> java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
>   
>>         at 
>>
>>     
> java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
>   
>>         at 
>>
>>     
> java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
>   
>>         at 
>>
>>     
> org.apache.jcs.utils.serialization.StandardSerializer.serialize(StandardSerializer.java:50)
>   
>>         at 
>>
>>     
> org.apache.jcs.utils.serialization.SerializationConversionUtil.getSerializedCacheElement(SerializationConversionUtil.java:73)
>   
>>         at 
>>
>>     
> org.apache.jcs.auxiliary.remote.RemoteCache.update(RemoteCache.java:207)
>   
>>         at 
>>
>>     
> org.apache.jcs.engine.CacheAdaptor.handlePut(CacheAdaptor.java:91)
>   
>>         at 
>>
>>     
> org.apache.jcs.engine.CacheEventQueue$PutEvent.doRun(CacheEventQueue.java:688)
>   
>>         at 
>>
>>     
> org.apache.jcs.engine.CacheEventQueue$AbstractCacheEvent.run(CacheEventQueue.java:607)
>   
>>         at 
>>
>>     
> org.apache.jcs.engine.CacheEventQueue$QProcessor.run(CacheEventQueue.java:575)
>   
>> Thanks!
>> -Josh
>>
>>
>>     
> ---------------------------------------------------------------------
>   
>> To unsubscribe, e-mail:
>> jcs-users-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail:
>> jcs-users-help@jakarta.apache.org
>>
>>
>>     
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


Re: ConcurrentModificationException

Posted by Aaron Smuts <as...@yahoo.com>.
This exception is being thrown from your object.  You
must have cached a collection, an array list.  Might
you have been modifying the object at the same time. 
remember, the cache holds references.  If you modify
an array list while you are iterating over it, you can
get a concurrent modification exception. 

Aaron


--- Joshua Szmajda <jo...@loki.ws> wrote:

> Hey all,
> 
> I'm using JCS with a Remote Cache Server and a
> number of web servers. 
> Now and then I'll get a
> ConcurrentModificationException as two of my 
> servers attempt to update the same key in a
> particular region at the 
> same time. Is there any good way to avoid this?
> Preferably I'd like each 
> server to be able to update the cache, and use
> whichever is put in last 
> as the 'real' version.
> 
> I was thinking I could use some sort of locking with
> each server having 
> its own key to update, then before each update a
> server would check all 
> servers' lock keys and only once they were all clear
> would it perform 
> whatever update it was going to do. This seems
> really slow though, and I 
> really need all the performance I can get.
> 
> Here's the stacktrace if it helps:
> 
> java.util.ConcurrentModificationException
>         at
> java.util.ArrayList.writeObject(ArrayList.java:572)
>         at
>
sun.reflect.GeneratedMethodAccessor142.invoke(Unknown
> Source)
>         at 
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at
> java.lang.reflect.Method.invoke(Method.java:585)
>         at 
>
java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:917)
>         at 
>
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1339)
>         at 
>
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
>         at 
>
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
>         at 
>
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
>         at 
>
org.apache.jcs.utils.serialization.StandardSerializer.serialize(StandardSerializer.java:50)
>         at 
>
org.apache.jcs.utils.serialization.SerializationConversionUtil.getSerializedCacheElement(SerializationConversionUtil.java:73)
>         at 
>
org.apache.jcs.auxiliary.remote.RemoteCache.update(RemoteCache.java:207)
>         at 
>
org.apache.jcs.engine.CacheAdaptor.handlePut(CacheAdaptor.java:91)
>         at 
>
org.apache.jcs.engine.CacheEventQueue$PutEvent.doRun(CacheEventQueue.java:688)
>         at 
>
org.apache.jcs.engine.CacheEventQueue$AbstractCacheEvent.run(CacheEventQueue.java:607)
>         at 
>
org.apache.jcs.engine.CacheEventQueue$QProcessor.run(CacheEventQueue.java:575)
> 
> 
> Thanks!
> -Josh
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> jcs-users-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org