• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread safe

 
Goan Balchao
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the information I gathered from reading the psecs the following elemnts are threadsafe.
1. Local variables
2. Instance variables
3. Request/Response attributes(because the request/response object is valid only in the currently executing thread)
and the non -thread safe elements are
1. Session attributes
2. Context attributes
3. Class variables
Am I correct? Have I left out any other elements?
ANy hellp will be appreciated.
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instance variables of a servlet are not thread safe by default.
According to the specs:
For a servlet not hosted in a distributed environment (the default), the servlet
container must use only one instance per servlet declaration...A servlet container may send concurrent requests through the service method of
the servlet. To handle the requests the developer of the servlet must make adequate
provisions for concurrent processing with multiple threads in the service method.

In short, it's up to you to make instance variables thread-safe.
-anthony
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic