• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Session object and clustering

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I plan to save an object in a session. For example, session.setAttribute("myObjectName", theObject);
Currently i have one server/web container only. My question is:
1) what if we need to cluster and may run the web application on 2 or more web containers - will i encounter any problem with the session?
2) If there are now two web containers and thus 2 or more jvms - do i need to serialize "theObject"?
3) If i use a primitive or a String instead of "theObjectReference" will this be an easier/better solution - i.e. i don't need to serialize etc.?
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a lot of overhead in having several web servers keeping track of one session, so you could run into performance issues if its a busy site. Last time I was working on something like that, we decided to go for sticky sessions. In that case, there were two web servers, but when a person hit the web site, they were assigned one server, and all requests by that person were serviced by the one machine. A load balancer was used to assign the session to the box that had the least amount of traffic at the time.
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Well, no problem, because you appplication server deals with almost all the things. However, your session could migrate from one machine to another, and because of that, all the object in the session MUST implement Serializable.
2) YOU don't need to serialize the object, you shoul turn the object serialuizable. In most cases you should only add "implements java.io.Serializable" to your class definition. The serialization, however, is done by the container. You also have some listeners that enable you to take some cares when the session is going to migrate from one machine to another (HttpSessionActivation).
3) You cannot add primitives as attributes to the session. But again, in most of the cases you only need to write "implements Serializable" in the objetc in order to let the server serialize it.
I think she's lovely. It's this tiny ad that called her crazy:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic