jQuery in Action, 3rd edition
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 Java Interview Guide this week in the Jobs Discussion 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: 13037
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 http://www.javaranch.com/name.jsp.
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: When to use SingleThreadModel?
It's not a secret anymore!