how to seriallize session attributes when using clustering at apache tomcat
I'm trying to do a session replication/clustering for my tomcat server,
and it doesnt seems to be working,
and i read from the apache site that mention
All your session attributes must implement java.io.Serializable
but i don't really know how to actually implement it,where to implement?
ppl who know how please help me up....
thanks a lot
# 1
In most cases you just need to add
implements java.io.Serializable
to any class that you want to Serialize. It is more of a marker interface than anything else. In most cases the default implementation is sufficient.
Find out the full info from the API: http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html
# 2
session replication is to keep the session information when the first server is down and continue running at the second server.
i'm not sure is there any class involve but the most important thing is to
get the information, which most of their value type is string.
for example,
session.setAttribute("username","tanck");
then server 1 down, i need server 2 to handle this session info,
what should i do?
# 3
I know what session replication is. You were asking about serialization, and how to implement that. So I explained how you implement Serialization on a bean.
I presume you are referring to [url http://tomcat.apache.org/tomcat-5.5-doc/cluster-howto.html] this page [/url] on how to set up clustering?
[url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html]java.lang.String[/url] implement the Serializable interface already. So strings should be ok.
If you have a class eg User then you need to write it as
public class User implements java.io.Serializable{
...
}
Thats it for making your beans Serializable.
For the rest of the clustering stuff, you need to read the Tomcat documentation.
What is it that "doesn't work" with your testing?