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 doubt about servlets 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 "doubt about servlets" Watch "doubt about servlets" New topic
Author

doubt about servlets

felix thomas
Ranch Hand

Joined: Jun 10, 2001
Posts: 89
hi,
I have a doubt. Can anyone tell me how a single servlet object handles mutiple clients.
eg. If i have a servlet name hello and around 4000 people access it at the same time. But only one object for the servlet will be created then how does the servlet handle multiple request keeping a separate identity for each clients
???
Paul Done
Greenhorn

Joined: Jan 03, 2003
Posts: 22
Typcially an application server maintains a HTTP thread pool to service the incoming HTTP servlet requests. On server start-up (or on first request depending on vendor), the single shared instance of the servlet is created. Each of the threads can call the service() method of the shared instance of the servlet. The service() (and do*()) methods are multi-threaded by default, therefore you have to be careful to synchronise the usage of members variables and other shared objects which are accessible from the servlet's methods. Many threads can be running in the same method instance.
The exception to this is if your servlet implements the SingleThreadModel marker interface. In these situations the server creates and executes an instance of the servlet object for each user agent session/request (note: some vendors use a pool of servlet instances to reduced memory footprint). In such cases only one thread ever runs in each instance of the servlet service() method at a time.
The server tracks a user's session by using a special JSESSIONID browser cookie or by using URL re-writing (by including a jsessionid parameter on each server url given to the browser in a html page).
Paul
[ January 09, 2003: Message edited by: Paul Done ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: doubt about servlets
 
Similar Threads
doubt in Sessin Migration
Regarding JNDI doubt
doubt
Basic Object Pooling doubt
doubt