This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes When to use SingleThreadModel? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "When to use SingleThreadModel?" Watch "When to use SingleThreadModel?" New topic

When to use SingleThreadModel?

Dez Max
Ranch Hand

Joined: Oct 01, 2002
Posts: 41
Hi Folks,
I've a doubt in using SingleThreadModel interface. I understand that it ensures no two thread can access the service method of the servlet that implements this interface at any given point in time. But practically when should we be using it. You guys have any idea. If so, a practical scenario would be appreciated.
Leena Diwan
Ranch Hand

Joined: Jun 18, 2001
Posts: 351
I too am waiting for this answer. A business requirement which forces us to go for a SingleThreadModel !

Thanks and Regards,

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
You would only use SingleThreadModel if it is impossible for some reason to write your servlet class without using instance variables to hold data related to the request.
I have never seen an example in real life code.
I would love to hear a description of business requirements that forced you to use SingleThreadModel.
Note that it simply ensures at each servlet instance only handles one request at a time. The servlet engine may create multiple instances.
[ December 13, 2002: Message edited by: William Brogden ]
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements.
It is sorta covered in the JavaRanch Style Guide.
subject: When to use SingleThreadModel?
Similar Threads
multiple get requests - one thread serving them all?
Single Thread Model
Q about servlet instances in containers.
Threading issues in servlet