This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS 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
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Objective 7.1  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Identify which Attribute Scope is thread Safe

Local variables
Instance variables
Class variables
Request attributes
Session attributes
Context attributes
I am still very confused which attribute scope is thread safe when we implement single thread model and which are when we do not implement Single thread model.
can anyone exlpain me this in details
thanks
nitin
 
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear NITIN,
when we say a servlet to be threadsafe, it means only one request thread can run within the service()method.This is normally achieved by implementing the singlethreaded model,by default servlets are not thread safe i.e the service () caters to more than one requests and allocates seperate threads to each request.so implementing single-threaded model in a way is nothing but obtaining the object lock for that particular instance(the object reference variable gets synchronized).But this interface doesn't gaurantee ...I mean this scenario can go wrong if u have a static memeber variable .Normally if u r implementing the single threaded model the container creates a pool of instances and allocates these instances to seperate requests ,now in this situtaion if u have a static memeber variable,it is shared by all the instances...so its no longer remains thread safe.So the inference is by default
1) Local Variables, and Request Attributes are thread-safe.
2)Instance Variables and Class Variables are not, but Instance variable become thread-safe if u implement singlethreadmodel, it does not guarantee u the same for class variable
3)Context and Session Attributes are not thread-safe by default as they are shared by multiple servlets and even the implementation of single threaded model does not make it thread-safe.We need to synchronize on the Session 0bject/Context Object if we want to make it thread-safe.
hope this helps
 
nitin shar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rishi
that was useful.

nitin
 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!