• 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

multiple concurrent request and handling by a servlet

 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If we want to restrict our servlet being accessed by multiple Thread, we can implement the SingleThreadModel interface to our servlet, why we can't use synchronized key word here?

Thanks in Advanced!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think carefully about the performance implications.

The reality of the situation is that servlets should be written to be thread-safe in the first place.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Think carefully about the performance implications.

The reality of the situation is that servlets should be written to be thread-safe in the first place.



I didn't get it! If we add synchronized to all methods, won't be it a Thread - safe?

Thanks in Advanced~!
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, of course not. Not allowing multiple threads to access code doesn't make the code thread-safe. It just prevents it from being an issue.

So let's say you're lazy and just synchronize your servlet code instead of writing it properly in the first place. What happens when two clients hit the servlet at the same time? What about ten clients? What about 100? 1000? 10,000?

reply
    Bookmark Topic Watch Topic
  • New Topic