aspose file tools
The moose likes Servlets and the fly likes Object references in a clustered container Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Object references in a clustered container" Watch "Object references in a clustered container" New topic
Author

Object references in a clustered container

Yohan Liyanage
Ranch Hand

Joined: Aug 17, 2007
Posts: 132

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?


Yohan Liyanage
http://blog.yohanliyanage.com
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Yohan Liyanage
Ranch Hand

Joined: Aug 17, 2007
Posts: 132

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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Mar 04, 2004
Posts: 26
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

Joined: Aug 17, 2007
Posts: 132

Thanks! Thats an amazing tool for sure.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2300
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


Rahul Bhattacharjee
LinkedIn - Blog
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Object references in a clustered container
 
Similar Threads
ServletContext over distributed JVMs
please help very urgent
Object cloning in HTTPSession?
Timer Task
Startup Servlet in weblogic clustered environment