wood burning stoves 2.0*
The moose likes Servlets and the fly likes Setting Context Attribute in Clustered Environment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Setting Context Attribute in Clustered Environment" Watch "Setting Context Attribute in Clustered Environment" New topic
Author

Setting Context Attribute in Clustered Environment

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
If there is a cluster of web containers, there should be 1 separate ServletContext instance per JVM. And, if we do a servletContext.setAttribute(), would that attribute auto populated to another JVM?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

There is nothing in the spec to mandate this.

Tomcat has session replication but nothing for context scoped objects.
Other servers may have a proprietary solution for this.
[ February 09, 2006: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
Does that mean in Tomcat, after we've set an context attribute in one servlet, there is no guarantee that another servlet can get it back - because the second servlet may be executed in another JVM?
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
It looks like. So, some people recommend to use database for storing attributes.


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Alec Lee:
Does that mean in Tomcat, after we've set an context attribute in one servlet, there is no guarantee that another servlet can get it back - because the second servlet may be executed in another JVM?


Yes.
Context scope is useful for caches, and global, reaonly attributes that get set when the application loads but not necessarily a good place to store request time generated values in a clustered environment.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting Context Attribute in Clustered Environment