aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Duplication of Servlet Context on each JVM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Duplication of Servlet Context on each JVM" Watch "Duplication of Servlet Context on each JVM" New topic
Author

Duplication of Servlet Context on each JVM

Edmund Yong
Ranch Hand

Joined: Nov 16, 2003
Posts: 164
In the HFSJ book, in the topic on session migration, it mentioned that the servlet context is duplicated on each server (one per JVM). So if there is two JVMs, does it mean that all the attributes in the servlet context in one JVM is exactly the same as those on the other servlet context in the other JVM? If a servlet in one JVM add an attribute to the servlet context, is the attribute immediately duplicated over to the other servlet context in the other JVM?

Thanks.


SCJP 1.2, SCWCD 1.4
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
good question..

i think the above process which is generally called Mirroring is basically done by webserver/webcontainer... i think this is automatically will be done by webcontainer...but it should know the url of other container..

Hey guys if i am write Please tell where to specify such url and for doing this thing ? tell the steps...


Thanks and Regards, Amit Taneja
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,

I don't think the context attributes are shared across all JVM. When you ( or container more specifically ) set the context attribute in one JVM it will not reflect in context of another JVM. That is why the contex attributes can not use to share common information in distributed environment. For this you have to use datadase of other way.

Thanks


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Edmund Yong
Ranch Hand

Joined: Nov 16, 2003
Posts: 164
If a servlet added an attribute to the context in one JVM, and another servlet in the other JVM (but still same web app) tried to read the attribute the context (which is a different context object), then it wouldn't be able to do so, right?

In that case, how can you ensure that context attributes are shared among servlets on different JVMs, but same web app?
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,

In that case, how can you ensure that context attributes are shared among servlets on different JVMs, but same web app?


I think there in no way. Did you know your request is process by which JVM in disributed environment. In the most of cases it is sheduled by Container, not manually by you. Therefore it is suggested to other mechanism like databases instead of context attributes. Atleast by reading the Servlet spec. I understand there is no provision to sync. the context attributes across all JVM in same web app.

I don't know if any web application server mirriored the context attributes across all JVM when added/changed/removed. If someone know please share to the forum.

Thanks
David Bridgewater
author
Ranch Hand

Joined: Apr 29, 2004
Posts: 44
As far as I'm aware, the only attributes which are shared in a distributed environment are session attributes.

Contexts can drift out of line with each other, and there is no mechanism mandated by the J2EE specs to solve this. I don't know of any commercial web server that does this either (I work with IBM WebSphere a lot, and while a lot of effort goes into session duplication, there is nothing to address context duplication).

I could imagine how you could build your own process (using a ServletContextAttributeListener) to keep contexts in line, but I'm with the previous person in the thread who said that anything that needs to be global (and changeable) for a web app goes in a database.

If context attributes are kept as "read only", they can't drift out of line.

Best,

David.
David Bridgewater
author
Ranch Hand

Joined: Apr 29, 2004
Posts: 44
Edmund...

Take a look at the servlet spec, 3.4.1

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.

Best,

David.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Duplication of Servlet Context on each JVM