EH Cache is throwing NotSerializableException exception

6,409 views
Skip to first unread message

Anurag Joshi

unread,
Apr 25, 2016, 6:29:15 PM4/25/16
to ehcache-users
  1. What version of Ehcache you are currently using;
  2. Paste the configuration for the Cache/CacheManager you have an issue with;
  3. Add any name and version of other library or framework you use Ehcache with (e.g. Hibernate);
  4. Providing JDK and OS versions maybe useful as well.

  1. We are using ehcache-core-2.3.2.jar 
  2. Paste the configuration for the Cache-;
defaultDisableInvalidation=false
defaultTimeToLiveSeconds=360
defaultMaxElementsInMemory=1000
defaultOverflowToDisk=true
defaultMemoryStoreEvictionPolicy=LRU
defaultMaxElementsOnDisk=100000
defaultDiskPersistent=false

     3. Add any name and version of other library or framework you use Ehcache with (e.g. Hibernate); Oracle ATG Commerce
     4 .Providing JDK and OS versions maybe useful as well - Linux 64 bit and java "1.8.0_91"

We are getting below mention exception while writing objects into disk.




SEVERE [net.sf.ehcache.store.compound.factories.DiskStorageFactory] (SCLStore.data:) [sessionId: BuOnPqsijNilDvpUMW9Udrfm.node18 profileId: 1541050000 ] Disk Write of DTOCacheKeysImpl [mDataMap={recordLimit=0, filterStateHashCode=-1202033242, cartridgeType=Header-TopMenu}] failed (it will be evicted instead): : java.io.NotSerializableException: com.endeca.infront.cartridge.RecordSpotlightSelection
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1181)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at java.util.HashMap.writeObject(HashMap.java:1133)
at sun.reflect.GeneratedMethodAccessor986.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:988)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1429)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1175)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1541)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:439)
at net.sf.ehcache.Element.writeObject(Element.java:787)
at sun.reflect.GeneratedMethodAccessor1069.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:988)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1429)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1175)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream.serialize(MemoryEfficientByteArrayOutputStream.java:97)
at net.sf.ehcache.store.compound.factories.DiskStorageFactory.serializeElement(DiskStorageFactory.java:327)
at net.sf.ehcache.store.compound.factories.DiskStorageFactory.write(DiskStorageFactory.java:306)
at net.sf.ehcache.store.compound.factories.DiskStorageFactory$DiskWriteTask.call(DiskStorageFactory.java:412)
at net.sf.ehcache.store.compound.factories.DiskOverflowStorageFactory$OverflowDiskWriteTask.call(DiskOverflowStorageFactory.java:247)
at net.sf.ehcache.store.compound.factories.DiskOverflowStorageFactory$OverflowDiskWriteTask.call(DiskOverflowStorageFactory.java:236)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
 
EHCacheException.txt

Louis Jacomet

unread,
Apr 26, 2016, 3:36:27 AM4/26/16
to ehcache-users
Hello,

As the exception indicates, what you put in the cache does not implement Serializable or contains a reference to something that does not.

And as soon as you use the disk store, this becomes a requirement.

Regards,
Louis

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.
To post to this group, send email to ehcach...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-users/a30d2f3d-5e02-4ddc-9bc8-a9f283f31816%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anurag Joshi

unread,
Apr 26, 2016, 7:11:12 AM4/26/16
to ehcach...@googlegroups.com

Hello,

Thanks for reply.
These are OOB exception we can not make them Serializable.
What should be the solution for that?

Increasing memory and disabling file writing is good idea?

defaultDisableInvalidation=true

defaultTimeToLiveSeconds=1000

defaultMaxElementsInMemory=10000

defaultOverflowToDisk=false

Thanks,
Anurah

You received this message because you are subscribed to a topic in the Google Groups "ehcache-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ehcache-users/KrZHJV_ViHE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ehcache-user...@googlegroups.com.

To post to this group, send email to ehcach...@googlegroups.com.

Fabien Sanglier

unread,
Apr 26, 2016, 7:53:32 AM4/26/16
to ehcach...@googlegroups.com
So you are saying you don't control this class 
"com.endeca.infront.cartridge.RecordSpotlightSelection" and cannot make it serializable?

If that's the case, then indeed your option is to not overflow to disk and stay strictly on heap.

For more options, visit https://groups.google.com/d/optout.


--
Fabien Sanglier
fabiens...@gmail.com

Alex Snaps

unread,
Apr 26, 2016, 8:59:08 AM4/26/16
to ehcach...@googlegroups.com
Another option would be to use Ehcache3.
It supports custom serializers, so these types could be serialized down to disk using some custom serialization mechanisms you would provide: http://www.ehcache.org/documentation/3.0/serializers-copiers.html
Alex


For more options, visit https://groups.google.com/d/optout.
--
Alex Snaps

Alex Snaps

unread,
Apr 26, 2016, 9:01:11 AM4/26/16
to ehcach...@googlegroups.com
btw, this could be down to disk, or to offheap with ehcache3... so you'd keep memory-access latency times, without having to grow your heap huge. That being said, if you can afford everything on heap (either it just works, or tune the GC to avoid too long pauses) and by reference, that will obviously get you the best results.
--
Alex Snaps

Swarnakshi Sawant

unread,
Oct 21, 2017, 1:20:26 PM10/21/17
to ehcache-users
hi Fabrien,

i faced same problem, tried setting overflowToDisk=false and overflowToHeap=true. But it seems to be still trying to push it to disk.
Anyother configuration i might need to add?? Please suggest.
CacheManager cacheManager = CacheManager.getInstance();
cacheManager.addCache(cacheTemp);
cacheTemp= cacheManager.getCache("cacheTemp");
cacheTemp.getCacheConfiguration().setEternal(true);
cacheTemp.getCacheConfiguration().setOverflowToDisk(false);
cacheTemp.getCacheConfiguration().setOverflowToOffHeap(true);
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-users+unsubscribe@googlegroups.com.

To post to this group, send email to ehcach...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-users/a30d2f3d-5e02-4ddc-9bc8-a9f283f31816%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "ehcache-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ehcache-users/KrZHJV_ViHE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ehcache-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-users+unsubscribe@googlegroups.com.


--
Fabien Sanglier
fabiens...@gmail.com

Fabien Sanglier

unread,
Oct 21, 2017, 2:51:02 PM10/21/17
to ehcach...@googlegroups.com
Overflow to offheap also requires serialization.

In ehcache2, not many options outside of implementing Serializable (if not possible, you'd have to set offheap to false and stay strictly on heap)

In ehcache3, like was said in this thread already, you could use custom serializers to serialize your objects (in which case you could leverage overflow to offheap or overflow to disk)

Hope that helps.

Thanks,

Fabien

To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.

To post to this group, send email to ehcach...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-users/a30d2f3d-5e02-4ddc-9bc8-a9f283f31816%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "ehcache-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ehcache-users/KrZHJV_ViHE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ehcache-user...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.


--
Fabien Sanglier

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.

To post to this group, send email to ehcach...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Fabien Sanglier
fabiens...@gmail.com
Reply all
Reply to author
Forward
0 new messages