This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Behaviour of HttpSession across multiple instances of tomcat

 
Huw Morgan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Huw Morgan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, that answers my question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic