What is a better approach for enabling thread-safe servlets and JSPs? SingleThreadModel Interface or Synchronization?

Although the SingleThreadModel technique is easy to use, and works well for low volume sites, it does not scale well. If you anticipate your users to increase in the future, you may be better off implementing explicit synchronization for your shared data. The key however, is to effectively minimize the amount of code that is synchronzied so that you take maximum advantage of multithreading.Also, note that SingleThreadModel is pretty resource intensive from the server's perspective. The most serious issue however is when the number of concurrent requests exhaust the servlet instance pool. In that case, all the unserviced requests are queued until something becomes free - which results in poor performance. Since the usage is non-deterministic, it may not help much even if you did add more memory and increased the size of the instance pool.

Showing Answers 1 - 1 of 1 Answers

vamshidhar Ghanpur

  • Aug 27th, 2005
 

I can answer this Good Question based on 2 requirements 1)Less volume sites 2)High volume sites. 
1)in case of less volume sites there will be less no of users,it means no of request are very less,in this case i can sugest go for SingleThreadModel,it can handle a single request at a time. 
the problem here is if sudenly request's increases then they will be maintained in a Queue,these requests have to wait until it gets resource,which leads to poor performance. 
2)in case of high volume sites,there will be more no of users it means that our application has to provide services for multiple requests at the same time, for this better to go for Synchronization concept,which is a Therad-safe concept.Synchronization is the capability to restrict multiple threads from being access to the shared resource. 
This is vamshidhar

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions