Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting Context Attribute in Clustered Environment

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like. So, some people recommend to use database for storing attributes.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic