• Post Reply Bookmark Topic Watch Topic
  • New Topic

Object references in a clustered container

 
Yohan Liyanage
Ranch Hand
Posts: 132
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I heard, if the servlet container is clustered, then requests will be handled by different servers in the cluster. Also, in such a situation, each JVM (server) will have its own servlet. If that is so, what happens to the object references made by the servlet? For example, if the servlet object refers to a particular object, which should be updated at each request, what will happen?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is yet another good reason to stay away from instance variables in servlets.

For containers that use session replication, make sure that any object bound to session (directly or indirectly) implements serializable and your session scoped objects will by synced by the container. Request scoped variables are always local to a particular request so they aren't affected by clustering.

Just as with instance variables in servlets, you want to make sure that any application scoped variables aren't specific to one node.
 
Yohan Liyanage
Ranch Hand
Posts: 132
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. You said that it is necessary to implement Serializable. Does this mean that these objects will be sent across the servers using RMI?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe it is up to the container builders to worry about how the are transported. I know Tomcat sends them over tcp but I don't know any more about it.
 
Joseph Kampf
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Yohan Liyanage:
Thanks. You said that it is necessary to implement Serializable. Does this mean that these objects will be sent across the servers using RMI?


Take a look at Terracotta http://www.terracotta.org. Not only can you cluster your sessions but you can cluster POJOs as well. The over head is not as bad as serializing the object every time it gets updated.




[BPSouther: Fixed link to terracotta]
[ August 17, 2007: Message edited by: Ben Souther ]
 
Yohan Liyanage
Ranch Hand
Posts: 132
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! Thats an amazing tool for sure.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No matter how you do session migration it certainly has come overhear.
There are some ways be which this migration can be minimized.

Might want to have a look at those.
Session Migration
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!