Forums Register Login

Duplication of Servlet Context on each JVM

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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...
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
Whose rules are you playing by? This tiny ad doesn't respect those rules:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1073 times.
Similar Threads
doubt about constraints of WEB-INF folder
about implicit objects
duplication of ServletContext !!!
ServletContext over distributed JVMs
Question on attributes
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:02:15.