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

thread safe static variables

 
santhoshkumar samala
Ranch Hand
Posts: 156
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if we declare static/instance variables in servlet as private then will it lead to thread safety of this variables?
 
Doyle Matt
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, no. because there's only one instance of a servlet. meaning for every request made there's only one instance but it will have a thread of execution per request.

so if you have a servlet class that has private static/instance variables it will be used for every request. if request1 did a change on an class or instance variable then request2 will see that change.

so basically the answer is no.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic