Two Laptop Bag*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Synchronizing the service method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Synchronizing the service method" Watch "Synchronizing the service method" New topic
Author

Synchronizing the service method

Arun Maalik
Ranch Hand

Joined: Oct 25, 2005
Posts: 216
Dear frien i am studing Head First Servlet JSP on page 196 It has been written that
"Synchronizing the service method would stop other threads from the same servlet from accessing the context attributes, but it don't do anything to stop a complitely diffrent servlet"
Okay i ma agree byt why it happen why synchronizing service method let other servlet execute the service method but but the servlet exist in same web can't execute the service method why?

Thanks and Regard

Arun
Amit Prakash Singh
Ranch Hand

Joined: May 11, 2006
Posts: 38
Hi Arun,

Every servlet has its own service method. Since you are synchronizing on a single serlvet, only that servlet's service method will run in a single thread at any time. Any other servlet doesn't get affected. thats the reason SingleThreadModel ensures the instance variable protection fot that servlet but not the context attributes.

Also context attributes are accessible by whole web-app, so any part of the application can access it and modify it anytime. So if you have to synchornize context attr., better get a lock on it first.


Amit Prakash Singh<br /> <br />SCJP 1.4 93% <br />SCWCD1.5 85%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Synchronizing the service method
 
Similar Threads
what's the use of synchronizing the service in servlet?
Multi Thread
Is Sessions thread safe if servlet implement SingleThreadModel interface ?
about SingleThreadModel?
When will be single threaded servlet mandatory to implement?