This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

threads and requests

 
Ali Khalfan
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to set something straight...are requests thread-safe?

let's say i'm in a controller servlet..




does this mean there is no way at all that concurrency can effect this?

p.s. this thread thing is getting me obsessed
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes they are. Request scope attributes and local method variables are thread safe, anything else is not, that includes:
- session attributes (since more than one request can be sent from the same client)
- application attributes (since all servlets share the same application/context and can access them anytime they wish)
- servlet's instance variables those variables defined in the body of the servlet (since any request to that servlet can access them)
 
Justin Russo
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.. but why was the request synchronized for the servlet below. This is for servlet generated by tomcat for a JSP.

snippet below copied from tomcat generated servlet

 
Ali Khalfan
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just come to think of it...technically the request attributes are not thread-safe are they....i mean no code will lock the request object. it's just that it is not possible (i think) two get something as two concurrent requests

is there?

have i got this right?
[ June 16, 2008: Message edited by: Ali Khalfan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic