aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets in Cluster environment" Watch "Servlets in Cluster environment" New topic
Author

Servlets in Cluster environment

Rizwan Mohammad
Ranch Hand

Joined: Sep 02, 2005
Posts: 445
Hi,
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.


Rizwan
SCJA, SCJP, SCWCD, SCBCD, SCDJWS.
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,

cheer.
gopinathang nathan
Ranch Hand

Joined: Oct 28, 2006
Posts: 41
check this posting - http://www.coderanch.com/t/363559/Servlets/java/run-code-server-startup
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.

Cheers!

-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: http://aspose.com/file-tools
 
subject: Servlets in Cluster environment
 
Similar Threads
****ServletContext and WebApplication confusion****
why config is read only???
Servlet Context in cluster environment - was6
Problem replicating ServletContext in the clustered environment
is ThreadLocal devil in clustering environment?