Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Are request scope attributes thread-safe? 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 "Are request scope attributes thread-safe?" Watch "Are request scope attributes thread-safe?" New topic
Author

Are request scope attributes thread-safe?

Aleksander Zielinski
Ranch Hand

Joined: Nov 11, 2005
Posts: 127
According to HFSJ they are, and from what I have learnt, only one thread at a time has access to a particural request object, that one thread that is currently "working" with that request (although would be very appreciated for answer to my another question below). Please check this link, they claim request attributes are not thread-safe.

http://www.javacamp.org/scwcd/course/7_1.html

My another questions is, if I dispatch the request to another servlet, do I still have a reference to the request object that I have dispatched? And am I able to set attributes for that request? When I tested it, set an attribute after I had dispatched the request to the JSP, servlet compiled, but I got null like there was no such attribute. So it seems I'm not, but would like to hear more about it. Thank you.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Hmmm... my inkling says they would not be thread-safe but in the real world it shouldn't matter too much. If you're crazy enough start kicking off multiple threads that all play with request objects, you probably have worse problems to deal with like how to keep your head on straight.

Your other question, it matters what you mean by "dispatch". If your dispatch forwards the request, everything stays in tact. But a redirect will create a new request and the old one goes bye-bye. Oh, and you always should have the ability to set and get attributes on a request.

Hope this helps.


A good workman is known by his tools.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Are request scope attributes thread-safe?