Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Servlets in Cluster environment

 
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.
 
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.
 
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.
 
Ranch Hand
Posts: 41
 
author and cow tipper
Posts: 5000
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.
 
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic