Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets in Cluster environment

 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
pawank gupta
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic