File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Thread safe servlets" Watch "Thread safe servlets" New topic

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
- 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
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:
subject: Thread safe servlets
It's not a secret anymore!