Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Thread safe servlets

 
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
 
Ranch Hand
Posts: 2713
  • 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)
 
author
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
 
Nothing up my sleeve ... and ... presto! A tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic