File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Thread safe servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Thread safe servlets" Watch "Thread safe servlets" New topic
Author

Thread safe servlets

Chris Salivar
Ranch Hand

Joined: May 25, 2001
Posts: 34
I have been dealing with this question for quite some time. Can anybody help me with figuring out which of the following attribute scopes are thread safe in case the servlet implements the SingleThreadModel interface as well as in case it does not
local variables
instance variables
class variables
request attributes
session attributes
context attributes
TIA
- Chris
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
local variables - always thread safe
instance variables/class variables - not thread safe
request attributes - thread safe
session attributes - not inheritly thread safe (multiple requests can belong to the same session)
context attributes - never thread safe (the servlet context is shared across all instances of the servlet)
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Christopher's list covers the case where SingleThreadModel is not implemented. When you implement SingleThreadModel in your servlet, the following change:
instance variables - thread safe
class variables - not thread safe
Everything else stays the same.
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread safe servlets