• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread Safety - request & response objects

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Originally posted by Xiaoxiao Lam :

So, Request-scoped attributes are thread-safe, right? Thank you.


Absolutely right.
 
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic