4

Previously we have implemented sticky session.

Here's the link on our environment: Sticky Session in apache doesn't work

Our next task is to implement session replication.

We are current using tomcat example, cart.jsp to demonstrate this behavior.

It is said that all session attribute must implement java.io.serializable.

Do you have any tips on where to implement it? We are following this tutorial closely.

tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html

Community
  • 1
  • 1
Wen Jun
  • 522
  • 3
  • 9
  • 19
  • I think we have implemented serializable correctly. The problem might be other things. Is there other tutorial we can follow to implement session replication? – Wen Jun Sep 16 '11 at 13:10
  • What is the error eaxctly? Are you losing session data? How are you testing this? If session stickiness is working, then do you need session replication? – JoseK Sep 19 '11 at 06:47
  • We are suppose to demonstrate sticky session and session replication to the class. Here is the test like: We are using tomcat example, date.jsp to demonstrate this. We set session.setAttribute("abc","123") in one machine and the other machine session.getAttribute. We will take down the first machine and the browser will still show 123 due to session replication – Wen Jun Sep 20 '11 at 09:20
  • or rather, how should i test if my session replication implementation is working? – Wen Jun Sep 20 '11 at 10:06
  • Your test case should be : Use only one browser and one machine. No need for 2nd machine. Set some attribute into the session, and on another JSP get it back from session. **AFTER THAT, bring down one server.** Then again hit your 2nd JSP. **If replication is working, you will still see your session attribute**. If you get null, it means replication is not working. Further do `out.print JSESSIONID` as well. you should see a new JSESSIONID but still get the correct value from session. – JoseK Sep 20 '11 at 10:31

1 Answers1

7

java.io.Serializable is a so-called marker interface. It contains no methods. So to make objects of some class serializable you don't have to implement anything. Simply add Serializable to the list of interfaces you class implements.

i.e.:

class MyClass implements Serializable {
}
aav
  • 2,514
  • 1
  • 19
  • 27
  • 1
    Also, the classes of all fields in `MyClass` must also implement `Serializable`, unless the field is declared `transient` -- in that case it's skipped by serialization and will assume it's default value when `MyClass` is deserialized. – Philipp Reichart Sep 16 '11 at 12:49
  • This is what we implemented. The problem might not lie in serializable. – Wen Jun Sep 16 '11 at 13:08
  • 1
    @Wen-Jun does every single object referenced by your objects also implement Serializable? Keep in mind that if you include system classes which don't, you'll need to find another solution. That error message should definitely mean what it says: that something going onto the session does not implement Serializable. – dbreaux Sep 16 '11 at 13:23