• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Single Threaded Servlet

 
kri shan
Ranch Hand
Posts: 1473
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why we go for Single Threaded Servlet ? What are the benefits ?
 
smitha verghese
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Its used when v need to protect the shared variables or the methods.

so only 1 thread at a time can access the instance.

its not appreciable to implement the single thread model interface since it would slow down the speed and hence forth , v use syncronized blocks or methods rather.

Let me know if u need more clarifications
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use of the SingleThreadModel is not considered a good idea.
If you think you have to use it, you probably need to rethink your servlet architecture. At one time there was a rumour that SingleThreadModel was going to be deprecated, but it is still in the servlet 2.4 API.
Bill
 
Divij Mahajan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Krishan

SingleThreadModel has very little in terms of benefits to offer, and thats in built synchronization, which like Smitha said can be achieved thru synchronized calls to the servlets..

However, there's a lot to loose, since servlets implementing this interface leave a large memory footprint and are are not effectively garbage collected. Also, when a servlet requires extra resources like a DB connection, it may open one connection per instance, which is not a good approach.

In essence, this model works nice for smaller applications but not for bigger ones.

-Divij
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic