• Post Reply Bookmark Topic Watch Topic
  • New Topic

multiple concurrent request and handling by a servlet

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • 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!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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?

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!