Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread safe servlets

 
Chris Salivar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic