[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
ArrayList and ConcurrentModificationException  XML
Forum Index -> Ehcache
Author Message
rune66

neo

Joined: 10/16/2013 06:39:22
Messages: 5
Offline

Hi there

I'm using EHCache to store ArrayList's and from time to time the EHCache throws a ConcurrentModificationException:

0 [wppage.data] ERROR net.sf.ehcache.store.disk.DiskStorageFactory - Disk Write of S. Hansen failed:
net.sf.ehcache.CacheException: Failed to serialize element due to ConcurrentModificationException. This is frequently the result of inappropriately sharing thread unsafe object (eg. ArrayList, HashMap, etc) between threads
at net.sf.ehcache.store.disk.DiskStorageFactory.serializeElement(DiskStorageFactory.java:401)
at net.sf.ehcache.store.disk.DiskStorageFactory.write(DiskStorageFactory.java:381)
at net.sf.ehcache.store.disk.DiskStorageFactory$DiskWriteTask.call(DiskStorageFactory.java:473)
at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1067)
at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1051)

I'm modifying the ArrayList-objects outside the cache.

I was wondering if one shouldn't use the thread unsafe class to store in EHCache at all? Would it help to use the Collections.synchronizedList-version (even though this requires syncronized keyword to be used when iterating) or should I use a different list implementation like Vector?

With regards
\Rune
alexsnaps

consul

Joined: 06/19/2009 09:06:00
Messages: 484
Offline

Right, anything you share across threads by making it available through the cache, needs to be thread safe one way or another... In this case, it just happens that an internal thread to Ehcache (that spills to disk) is accessing the entry, but it could be any other thread in your application.

Or you make sure every entry is copied on read/write or both. Comes at a higher cost, but makes sure no single instance is ever accessed from different threads.

Alex Snaps (Terracotta engineer)
rune66

neo

Joined: 10/16/2013 06:39:22
Messages: 5
Offline

Ok yes it's of course obvious but then I'm not sure wether Collections.synchronizedList-version is safe "enough" since it requires syncronized keyword to be used when iterating and I was wondering if that could be an issue in EHCache. On the other hand why should EHCache need to iterate over an object in the cache ...
 
Forum Index -> Ehcache
Go to:   
Powered by JForum 2.1.7 © JForum Team