简体   繁体   中英

Clustering with shared session - object not serialized error

I have an environment where 2 load-balanced clustered tomcats pointing to same application.

When they run under sticky session and not shared session, they works fine. Now I am implementing failover for tomcat. ie If one one fails other handles the sessions that handled by the failed one. And I am trying in-memory session replication.

When I enable this feature, I am getting some exceptions like

org.apache.catalina.ha.session.DeltaManager requestCompleted SEVERE: Unable to serialize delta request for sessionid [68930629D2318EFAC06F3D75FFA162D0.tomcat2] java.io.NotSerializableException: org.json.JSONObject at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326) at org.apache.catalina.ha.session.DeltaRequest$AttributeInfo.writeExternal(DeltaRequest.java:374) at org.apache.catalina.ha.session.DeltaRequest.writeExternal(DeltaRequest.java:272) at org.apache.catalina.ha.session.DeltaRequest.serialize(DeltaRequest.java:287) at org.apache.catalina.ha.session.DeltaManager.serializeDeltaRequest(Del taManager.java:640) at org.apache.catalina.ha.session.DeltaManager.requestCompleted(DeltaManager.java:1120) at org.apache.catalina.ha.tcp.ReplicationValve.send(ReplicationValve.java:550) at org.apache.catalina.ha.tcp.ReplicationValve.sendMessage(ReplicationValve.java:537) at org.apache.catalina.ha.tcp.ReplicationValve.sendSessionReplicationMessage(ReplicationValve.java:519) at org.apache.catalina.ha.tcp.ReplicationValve.sendReplicationMessage(ReplicationValve.java:430) at org.apache.catalina.ha.tcp.ReplicationValve.invoke(ReplicationValve.java:363) at org.apache.catalina.ha.session.JvmRouteBinderValve.invoke(JvmRouteBinderValve.java:210) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190) at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291) at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769) at org.apache.jk.common.ChannelSocket.processConnection(Channe lSocket.java:698) at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690) at java.lang.Thread.run(Thread.java:619) Sep 11, 2009 7:21:06 PM org.apache.catalina.ha.session.DeltaManager requestCompleted SEVERE: Unable to serialize delta request for sessionid [68930629D2318EFAC06F3D75FFA162D0.tomcat2] java.io.NotSerializableException: org.json.JSONObject

Since JSON is not serialized I am putting it inside an ArrayList before setting it in session. And it works fine in non shared session environment.

What I need to do for enabling fail over? (Please done tell something like don't save the object in session. Its not only the one object which causing error. I am getting errors for other objects like Data source etc.. as well)

Thanks in advance

Umesh

Edit: Have already implemented serialization and transient

public class ABC implements Serializable { private static final long serialVersionUID=2007L; public static transient DataSource source;

Getting this error java.io.NotSerializableException: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper ... storing attribute 'ABC' with value NOT_SERIALIZED

您需要将其放入对象内,并在其中存储引用的字段标记为瞬态。

If you can control the objects AND need them, then implement serializable & the necessary readObject(), writeObject() methods.

Any objects that fail either need to be extended to implement serializable, or not stored in the session directly, but placed in another object as a transient field. You need to make your application robust enough to rebuild these objects after the failover happens.

确保在写入会话内容时必须实现java.io.Serializable接口

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM