wood burning stoves 2.0*
The moose likes Servlets and the fly likes SingleThread Model 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 "SingleThread Model" Watch "SingleThread Model" New topic
Author

SingleThread Model

rex tony
Ranch Hand

Joined: Aug 29, 2007
Posts: 159
What is SingleThread Model?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

It is a deprecated API.

In a nut shell, if a servlet implements Single Thread Model, the container will provide a new copy of it for each request. It was deprecated because its name gave the false impression that implementing it guaranteed thread safety.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

If a servlet is implementing SingleThreadModel thn container will synchronize access to service(). threre can not be more thn one thread running through service method.

Yes, it is deprecated


[Servlet tutorial] [Servlet 3.0 Cook Book]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Originally posted by sudhir nim:
If a servlet is implementing SingleThreadModel thn container will synchronize access to service()


No, this is one way in which it can be implemented.

From the API:
The servlet container can make this guarantee by synchronizing access to a single instance of the servlet, or by maintaining a pool of servlet instances and dispatching each new request to a free servlet.
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

Ya thats true.
Whatever the case, container guarantees that only one thread is accessing service() method at a time.

It is irrelevant, I think programmer doesnt need to know weather container is
synchronizing the access or maintaining the pool.
[ November 05, 2007: Message edited by: sudhir nim ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

It's not irrelevant, it's the API.
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

Its transparent to developer.
Developer doesnt need to know it.
What one could achieve if he know that container has pooled the servlet instances and not synchronized the service method()?

You may correct me if I am wrong.
[ November 05, 2007: Message edited by: sudhir nim ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Instance variables, which shouldn't be used in the first place, will behave differently under those differing scenarios.

But what it all comes down to is that it is deprecated and should never be used.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SingleThread Model
 
Similar Threads
singlethreadmodel
Is Servlet SingleThread Model or Multithread Model by default?
This Weeks GiveAway:
Shared Access
singlethreadmodel