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 ???
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 ]