Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

threads and requests

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic