• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Context in Distributed Environment

 
Tejas Tambe
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With reference to Hanumant Deshmukh's book,
Chapter 6, Section 6.4.1
Behaviour od servlet context in distributed environment
Its' mentioned that
A servlet container is not required to propogate ServletContextEvents and ServletContextAttributeEvents to differnet JVMs. This means that changes to the ServletContext in one JVM may not trigger a method call on a ServletContextListener or a ServletContextAttributeListener in another JVM.

Now the question asked in the quizlet right after section 6.4.1,
Your web application user ServletContextListener to page support personnel whenever it goes down. What would be the impact on this functionality if the ewb application were deployed is a distributed environment ?

The answer given is that, there won't be any effect.
But the statement made, kind of contradicts with the answer given to this question.
Can any one clear my doubt !!!
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each JVM has a single instance of ServletContext per web application. The explanation was right and so is the question/answer part. When a particular ServletContext (also known as web application) is garbage collected for some reason, you can add a listener to page the support person. There is no communication here between the containers or JVMs. If multiple ServletContext instances are destroyed, support person will be paged multiple times.
Hope that helps.
 
S. Ganapathy
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tejas Tambe,
Please dont get confused with all those now. Go ahead, and complete the book first. Then those topics, where u have doubts, read once again. Surely you will get clarification for ur doubts.
Most of the listeners behave similar in single context as well as in multiple contexts(distributed environments) with the major difference is when a context is destroyed due to server crashes in distributed environemnt, the session in that context is exported to another available context. Rest everything is same. So in a distributed web applications, user can rely session binding events.
At this stage it will be confusing. So please go ahead of the book, and give a second read. Also try to read the appropriate topics in servlet specifications.
GVRao
 
Sowmya Sridhar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the confusion is because there are 2 different things listed. One is the ContextAttributeListener and the other is the ContextListener itself. The book is referring to the attributes in the Context, not the Context itself. See the picture now?!
 
S. Ganapathy
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi nikhil krish,
This is regards to your private message "regarding default web application",

This is with regard to your posting on the forum.
Can you kindly explain me about default web application, which you had mentioned below
I do agree with Jessica. There is one instance of ServletContext per JVM in a distributed web application, but default web application (ROOT in case of Tomcat) has only one instance among multiple JVMs in a distributed environment.
At this stage, Tejas Tambe, you will get confused. Give a through read of the entire book, surely you will understand in later chapters. Don't worry about this at this stage. Your question is answered in the book.

From Deshmukh's book:
B"y default, an instance of a web application must run on one VM at any one
time. This behavior can be overridden if the application is marked as
"distributable" via its deployment descriptor."
According to servlet specification 2.3, SRV3.2:
There is one instance object of the ServletContext interface associated with each
web application deployed into a container. In cases where the container is
distributed over many virtual machines, a web application will have an instance of
the ServletContext for each VM.
Servlets in a container that were not deployed as part of a web application are
implicitly part of a 'default' web application and have a default ServletContext.
In a distributed container, the default ServletContext is non-distributable and
must only exist in one VM.
Hope your doubt got cleared.
GVRao
 
Ken Januski
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems to me, and I realize I might be wrong, that the confusing part here is "propagate ServletContextEvents and ServletContextAttributeEvents to different JVMs." Because each JVM has its own ServletContext it responds to its own events, and thus notifies support personnel when server goes down. If this were not the case and each JVM needed a ServletContextListener for other JVMs in order to alert support personnel when another JVM went down then there would be a problem with the answer since JVMs would not necessarily get the notification of another JVM going down. But since the Listener only needs to listen to its own events, which it can do since it has its own ServletContext, there is no problem.
Is this correct? I think it is and hope it explains the problem a little more clearly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic