File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlets in Cluster environment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets in Cluster environment" Watch "Servlets in Cluster environment" New topic

Servlets in Cluster environment

Rizwan Mohammad
Ranch Hand

Joined: Sep 02, 2005
Posts: 445
If I have 2 jvms in my cluster, will I have two servletcontext objects? If I set attribute in application scope(servlet context) and it sets in one jvm then can I get the same value from other jvm's servlet context, if it happens to go to the next jvm in my next call?
Please clarify. Thanks in advance.

Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I checked this post few days back.Till now there are no replies for this.Have you found the answer to this ?
if yes please post.

Rahul Bhattacharjee
LinkedIn - Blog
pawank gupta
Ranch Hand

Joined: Jun 07, 2006
Posts: 34
In the clustered environment you can only share the session data within servers and this process will take care by your manager class that you declared in server.xml. so if there any method to get servlet context from session then you can. but i dont think there is any,

gopinathang nathan
Ranch Hand

Joined: Oct 28, 2006
Posts: 41
check this posting -
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

I can speak with WebSphere experience, where the ServletContext is not synchronized across JVMs. The ServletContext should be used for objects that are largely read, and rarely written to, and when they are written to, a lack of synchronization across ServletContexts will not be detrimental to the JVM.

A good job for an object in a ServletContext is a component that marshals requests to an underlying central database. The object can always easily be pulled from the ServletContext, but the actual DATA is pulled from a central location, ensuring the data is always in sync.

Also, be careful of the size of the objects you put into the ServletContext. You don't want the ServletContext eating up too much of your memory.


-Cameron McKenzie
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Below text I have taken from servlet spec.

SRV.3.4.1 Context Attributes in a Distributed Container
Context attributes are local to the JVM in which they were created. This prevents
ServletContext attributes from being a shared memory store in a distributed
container. When information needs to be shared between servlets running in a
distributed environment, the information should be placed into a session (See
Chapter SRV.7, Sessions), stored in a database, or set in an Enterprise
JavaBeansTM component.
I agree. Here's the link:
subject: Servlets in Cluster environment
It's not a secret anymore!