• 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

Context/Session Thread safety

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone tell me if these two code snippets do the same thing and if not what the specific difference is:

synchronize(getServletContext()) {
....
}

compared to

ServletContext mySC = getServletContext();

synchronize(mySC) {
.....
}

And is the answer the same for synchronizing on sessions (I would assume so but want to be sure) as listed below:

synchronize(getSession()) {
.......
}

HttpSession mySession = getSession();

synchronize (mySession) {
...........
}

Thanks for your time,
Greg
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont see any difference there. You could test it out buddy. It should be fine I guess. In both cases the same object is beign referenced.

-Ritesh
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only difference is that in the first your reference to the context expires at the end of your synchronised code block. But I don't see how knowing this or not knowing it would help or deter you in the exam.
reply
    Bookmark Topic Watch Topic
  • New Topic