File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Thread Safety - request & response objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Thread Safety - request & response objects" Watch "Thread Safety - request & response objects" New topic
Author

Thread Safety - request & response objects

Bhavik Patel
Ranch Hand

Joined: Jul 12, 2004
Posts: 155
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


SCJP 1.4<br />SCWCD 1.4(91%)<br />Working on SCJD -Bodgitt & Scrapper Constructions...<br /> <br />"It takes 43 muscles to frown & 17 to smile but it doen't take any to just sit there with a dumb look on your face .. Keep Smiling "
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
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


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Xiaoxiao Lam
Greenhorn

Joined: Mar 04, 2006
Posts: 27
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!!


SCJP 1.4<br />SCWCD 1.4
Ernesto Leyva
Ranch Hand

Joined: Feb 23, 2006
Posts: 62
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

Joined: Mar 04, 2006
Posts: 27
So, Request-scoped attributes are thread-safe, right? Thank you.
Bhavik Patel
Ranch Hand

Joined: Jul 12, 2004
Posts: 155
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

Joined: Sep 16, 2005
Posts: 120
Originally posted by Xiaoxiao Lam :
So, Request-scoped attributes are thread-safe, right? Thank you.

Absolutely right.


Regards,<br />Ram.<br />SCJP 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread Safety - request & response objects