• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Session object and clustering

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
HTH
Damien
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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.
Dani
 
The knights of nee want a shrubbery. And a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic