This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Duplication of Servlet Context on each JVM

 
Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic