aspose file tools*
The moose likes Servlets and the fly likes SingleThreaded+synchronized Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "SingleThreaded+synchronized " Watch "SingleThreaded+synchronized " New topic
Author

SingleThreaded+synchronized

Rakesh Sahadevan
Greenhorn

Joined: Jul 11, 2004
Posts: 12
Is it possible to replace SingleThreaded model with synchronized keyword in
service method?
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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

Joined: Jul 11, 2004
Posts: 12
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SingleThreaded+synchronized