aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Context/Session Thread safety Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Context/Session Thread safety" Watch "Context/Session Thread safety" New topic
Author

Context/Session Thread safety

Greg Lamonakis
Greenhorn

Joined: Mar 18, 2005
Posts: 4
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
ritesh hk
Greenhorn

Joined: Mar 15, 2005
Posts: 6
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


-------------<br />SCJP 1.4 <br />SCWCD (just started)
James Christian
Ranch Hand

Joined: Apr 04, 2005
Posts: 63
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.
 
 
subject: Context/Session Thread safety