Tomcat's Cluster function Copy the session when copying the object?

xiaoxiao2021-03-05  21

Question: How do you copy these objects when you use SSESSION to save some objects?

Tomcat5 has considered the problem caused by this cluster, in fact, is the problem of Cluster. If you use Tomcat's Cluster solution, I believe that you should guarantee synchronization of information such as session.

In addition, Tomcat requires the object to be placed in the session to implement serializable to ensure that each object can be replicated normally.

Some people ask questions that Session uses MAP to save data, and the actual object is not serialized when serialization. In fact, look at the HashMap serialized code, you can know that during session serialization, it is possible to correct data objects saved in Map. More importantly, when Tomcat serialization, there is no serialization of HashMap, but reads out of the respective sequence of objects.

So the object instance saved to the session should also be copied.

This ensures that the memory data on each server is the same.

Another problem is that many people are worried about Tomcat's performance issues, in fact, some content information such as session is not very big, especially in several workstations belong to the same network. I want to have the horizontal extension performance, I can ignore, I think.

reference:

Session serialized in Tomcat:

Protected Void WriteObject (ObjectOutputStream Stream) throws ioException {

// Write the scalar instance variables (except Manager) stream.writeObject (new Long (creationTime)); stream.writeObject (new Long (lastAccessedTime)); stream.writeObject (new Integer (maxInactiveInterval)); stream.writeObject (new Boolean (isnew); stream.writeObject (isvalid); stream.writeObject (new long (thisaccessedtime); stream.writeObject (ID); if (debug> = 2) log ("WriteObject () Storing Session ID);

// Accumulate the names of serializable and non-serializable attributes String keys [] = keys (); ArrayList saveNames = new ArrayList (); ArrayList saveValues ​​= new ArrayList (); for (int i = 0; i = 2) log ("storing attribute '" Savenames.get (i) "'with value'" Savevalues.get (i) "');} catch (notserializableExcection e) {log (sm.getstring (" standardsession.notserizable ", Savenames.get (i), ID), E) Stream.writeObject (not_serialized); if (debug> = 2) log ("Storing Attribute '" Savenames.get (i) "' with value not_serialized");}}

}

HashMap serialized code:

private void writeObject (java.io.ObjectOutputStream s) throws IOException {// Write out the threshold, loadfactor, and any hidden stuff s.defaultWriteObject (); // Write out number of buckets s.writeInt (table.length);

// Write out size (Number of mappings) s.writeint (size);

// Write Out Keys and VALUES (Alternating) for (iTerator i = entryset (). Iterator (); I.hasNext (); {map.entry E = (map.entry) i.next (); s.writeObject (E.GetKey ()); s.writeObject (E.GetValue ());}}

转载请注明原文地址:https://www.9cbs.com/read-38634.html

New Post(0)