Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Safety - request & response objects

 
Bhavik Patel
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was thinking that attribute in request or response is thread safe ..but i read in the specs that they are not so when setting an attribute in request object we have to synchronize that code...I was thinking the only way request object is not thread safe is if we store its reference and use it later on ..But one another question how its possible to use the request reference after the servlet life cycle is over...For reference pls go on page 28 SRV 2.3.3.3.3 in Servlet specs
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think the request object is thread safe. The problem is about the attributes set in the request scope. The Attributes Objects are reference to the other objects with some attribute name , so there may be some other links to that object which can modify the object when the any service method is running.

Thanks
 
Xiaoxiao Lam
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But in HFSJ book, it is said that Request-scoped attributes are thread-safe. Anyone can explain or correct me if I am wrong? Thank you!!
 
Ernesto Leyva
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every time your browser sends an HTTP request the Web container will create a new request and response object. Those objects and their attribute-sets of objects will stay alive until the service method is done.
Then the container will set those objects to be garbage-collected.

Only the session, context attributes are preserved so other servlets can reuse them
 
Xiaoxiao Lam
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, Request-scoped attributes are thread-safe, right? Thank you.
 
Bhavik Patel
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone read page 28 SRV 2.3.3.3.3 in Servlet specs and answer the question with reference to it ..It clearly says that request object is not thread safe on that page in Servlet specs 2.4
 
Ramasubbhu Allur Kuppusamy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Xiaoxiao Lam :
So, Request-scoped attributes are thread-safe, right? Thank you.

Absolutely right.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic