Session Replication Failing With The Exception java.io.NotSerializableException
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.x
- 7.x
Issue
-
In EAP 6, serialization fails with the following ERROR:
ERROR [org.infinispan.interceptors.InvocationContextInterceptor] (ajp-/10.1.2.3:8009-2) ISPN000136: Execution error: org.infinispan.CacheException: java.lang.RuntimeException: Failure to marshal argument(s) ... Caused by: org.infinispan.marshall.NotSerializableException: this.is.my.object Caused by: an exception which occurred: in field myField in object java.util.HashMap@3ceddee4 in object org.jboss.as.clustering.SimpleMarshalledValue@3ceddee4 in object org.infinispan.atomic.PutOperation@20530a83 in object java.util.LinkedList@f2784c57 in object org.infinispan.atomic.AtomicHashMapDelta@13452861 in object org.infinispan.commands.write.PutKeyValueCommand@e593a539 in object org.infinispan.commands.tx.PrepareCommand@7acfe1a3
Resolution
Make sure all classes put in the session are Serializable.
- All members of a Serializable class must also be Serializable or marked as transient.
Or Disable clustering to avoid session replication.
Log4j
If an object in the session has a log4j Logger in it, but the Log4J Loggers are not serializable you can do one of two things
- Mark the logger as transient ( if you are using a separate logger for each instance)
- Mark the logger as static
Root Cause
The NotSerializableException will occur whenever a non-serializable class resides in the session and the session is replicated.
JBoss EAP has no way to serialize a class that does not implement the Serializable
interface. It will, therefore, throw an exception
. Note that clustering will not work properly if this issue is not resolved, this is because the marshalling process, i.e passing converted information from POJO
to the wire is a vital process on the cluster. The marshalling process is based on the JBoss Marshalling Framework, instead of Java framework for improving the performance.
The purpose of clustering is to achieve high availability, which is achieved through replication. The NotSerializableException error hinders replication and interferes in this process.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments