• Post Reply Bookmark Topic Watch Topic
  • New Topic

ServletContext and thread safe

 
Hari babu
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
When i add an object to the ServeltContext to make that object as application scope, is that operation a thread safe if not how do i take care of that ?
Hari
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are worried about multiple requests adding the object to the ServletContext, put your code that adds to the ServletContext in a block synchronized on the ServletContext.
If the object you place in application scope gets modified, you certainly must consider thread safety since multiple requests can see it. Just synchronize on the object before modifying it.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!