• 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

Synchronizing the service method

 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic