Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread Safety question  RSS feed

 
James Dekker
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What mechanism determines a servlet's thread safety? Is it the container or the implementation of the servlet class?

Thanks again!
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An implementation of servlet classes.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're not sure how to create a thread safe servlet, follow this basic rule of thumb:
Don't create instance variables.

You could still run into concurrency issues if your servlets or JSPs try to access a session or context scope object at the same time but instance variables are the leading cause of threading problems in servlet applications.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!