• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SingleThreaded+synchronized

 
Rakesh Sahadevan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to replace SingleThreaded model with synchronized keyword in
service method?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rakesh Sahadevan:
Is it possible to replace SingleThreaded model with synchronized keyword in service method?
Yes. Is it a good idea? No. If you implement the (deprecated) SingleThreadModel, the container will create as many instances of the servlet as needed to handle the load. If you simply synchronize the service() method, you get just one instance, which might well become a bottleneck under high loads.

- Peter
 
Rakesh Sahadevan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya peter. you are correct.Actually its an interview question!!!
Yes. Is it a good idea? No. If you implement the (deprecated) SingleThreadModel, the container will create as many instances of the servlet as needed to handle the load. If you simply synchronize the service() method, you get just one instance, which might well become a bottleneck under high loads.
Thank u
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic