• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HttpServletResponse

 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was going through one of the examples in the SCWCD Exam Study Kit by Hanumant Deshmukh and Jignesh Malavia. The example is on p268.
...
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
...
synchronized (request)
{
...
}
}
I don't understand when you would ever need to synchronize on request? The request variable is a local variable. Unless you are passing the request variable explicitly to another thread I don't see why this would be done?
 
Terry McKee
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any thoughts on this?
 
Terry McKee
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would really like to find out what other people have discovered on this issue.
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya,
There is no need to synchronize the request object in service method.
Raj Paul
 
Author
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Terry!
Yes, you are right. The request scoped objects are always thread-safe. But the request object in the servlet code on p268 is synchronized because it is explained in the context of JavaBeans as discussed here http://www.manning.com/ao/readforum.html?forum=scwcdao&readthread=18
You can also post more questions about the book or read answers to other queries at http://www.manning.com/getpage.html?project=deshmukh&filename=forum.html
Hope, the bookproves helpful to you.
-j
 
Terry McKee
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies. I took a look at the link you provided Jignesh. I am still a little confused on this point, but I'll figure it out. Anyway, your book is really great, I have gotten a lot out of it.
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic