This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion 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

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.

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

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:
subject: Are request scope attributes thread-safe?
It's not a secret anymore!