This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Servlets and the fly likes Single Threaded Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Single Threaded Servlet " Watch "Single Threaded Servlet " New topic

Single Threaded Servlet

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1393
Why we go for Single Threaded Servlet ? What are the benefits ?
smitha verghese
Ranch Hand

Joined: Jun 21, 2003
Posts: 42

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

Joined: Mar 22, 2000
Posts: 12982
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.
Divij Mahajan

Joined: Jul 26, 2004
Posts: 8
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<br />---------------------------------<br />Weinberg's Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization.
Don't get me started about those stupid light bulbs.
subject: Single Threaded Servlet
It's not a secret anymore!