File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "doubt about servlets" Watch "doubt about servlets" New topic

doubt about servlets

felix thomas
Ranch Hand

Joined: Jun 10, 2001
Posts: 89
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

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).
[ January 09, 2003: Message edited by: Paul Done ]
I agree. Here's the link:
subject: doubt about servlets
jQuery in Action, 3rd edition