File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Behaviour of HttpSession across multiple instances of tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Behaviour of HttpSession across multiple instances of tomcat" Watch "Behaviour of HttpSession across multiple instances of tomcat" New topic
Author

Behaviour of HttpSession across multiple instances of tomcat

Huw Morgan
Greenhorn

Joined: Mar 07, 2006
Posts: 23
I am developing a web site using JSP's that will be provided from tomcat running on 2 web servers with the load distributed by a load sharing switch. This means that any one request could go to either server and so to either one of 2 (or more) JVM's. I need to save information about a clients session.

If this was running on 1 web server I would save the data as an object in the HttpSession (ie. using the request.getSession().setAttribute and request.getSession().getAttribute methods). In the API doc it has one slightly criptic phrase [1] "When container migrates a session between VMs in a distributed container setting, all session attributes implementing the HttpSessionActivationListener interface are notified." This seems to indicate that in my situation it is possible to access the same instace of HttpSession across 2 or more JVM's though I am not sure how this would be done (perhaps by serializing the data in a cookie?). Unfortunatly the load bearing switch is not yet set up so I cannot test it before I start coding.

Does anyone know if it is possible to share session data in this way? Thanks for any help.

Hugh

[1] http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSession.html
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Yes, Tomcat supports clustering via session replication.

If you poke around a bit, you should be able to find some articles on the web that show you how to use an instance of the Apache Web Server (httpd) as front end to a cluster of Tomcat nodes. This is one way you could test this before your switch is up and running.

Since this is really more of a Tomcat question than a JSP one, I'm going to move this to our Tomcat forum.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html
Huw Morgan
Greenhorn

Joined: Mar 07, 2006
Posts: 23
Thank you very much, that answers my question.
 
 
subject: Behaviour of HttpSession across multiple instances of tomcat
 
Similar Threads
get the session time out value from the web.xml
Persistence session
How to create Session
Using a Session Attribute in another Servlet
Is it possible to create more than one HttpSession in our Application