top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

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

+1 vote
300 views
What’s a better approach for enabling thread-safe servlets and JSPs? SingleThreadModel Interface or Synchronization?
posted Sep 24, 2015 by Shyam

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

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.

answer Sep 28, 2015 by Karthick.c
...