• 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

How to make servlet Context attribute thread safe

 
Ranch Hand
Posts: 61
Firefox Browser Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Recently I was reading Head First JSP where it was explained that servlet Context attribute are not thread safe.I understood the concept.then it was also explained that how to make it thread safe.In which one solution given was to make service() method synchronized.but writer rejects this option saying that if we make service method synchronized it would stop other thread from same servlet accessing the context attributes,but it will not do anything to stop a thread from completly different servlet..Here friends its ok that it cccan not stop thread from other servlet but why it will not stop thread for same servlet.It mean that thread for same servlet are based on same object thats why they conflict each other.
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

but why it will not stop thread for same servlet.It mean that thread for same servlet are based on same object thats why they conflict each other.


It will stop others to access the same servlet (and the servlet context attributes). Note that there will be one instance of a servlet.

Regards,
Frits
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic