permaculture playing cards*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Single Threaded Servlet " Watch "Single Threaded Servlet " New topic
Author

Single Threaded Servlet

kri shan
Ranch Hand

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

Joined: Jun 21, 2003
Posts: 42
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

Joined: Mar 22, 2000
Posts: 12676
    
    5
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


Java Resources at www.wbrogden.com
Divij Mahajan
Greenhorn

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


-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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Single Threaded Servlet
 
Similar Threads
zahara
single-threaded
what is single threded model
servlet concepts
By Default Servlet is Single-Thread Model or Multi-Thread Model ??