Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_java_server thread: Servlet life cycle and its behavior with multiple requests?


Message #1 by "Tom Barns" <mohseif@y...> on Thu, 5 Apr 2001 20:08:06
Hi  Tom ,

If you are not implementing the SingleThreadModel  interface then the 
server will creates only one instance of the servlet and all the request 
threads will be operates with that instance only if the methods are not 
synchronized then i think the server will runs the schedulers to work out 
the requests, if you are making use of any shared resource such as static 
variable or static methods then in such case it needs to take care 
otherwise the data will be loosed, for data sharing between the servlets 
you can make use of the sessions so that per request thread you can 
maintain the unique data's .

Rgds

Ravi

>From: "Tom Barns" 
>Reply-To: "Java Server" 
>To: "Java Server" 
>Subject: Servlet life cycle and its behavior with multiple requests? 
>Date: Thu, 5 Apr 2001 20:08:06 
> 
>As we know that we send send a request for a servlet on the server, 
>the server will create just ONE INSTANCE of that servlet. 
>in other words just we have one object of that servlet,the life for that 
>object 
>is based on the life of our server and it will be alive as long as our 
>server is running. 
>let us say we need to send 50 requests almost in the same time to that 
>servlet. 
>what I undersatnd the JVM that runs that object will creates 50 threads 
>for those 50 requests. 
>my question is: Are those threads going to execute piece of code(a method 
>within the servlet class) 
>(assuming that the piece of code(The method) is NOT SYNCHRONIZED) in the 
>same time? 
>or the second thread for the second request will wait till the first 
>thread of the first 
>request finish execution that piece of code. 
>are we going to have multiple copies of those memebers of that object(i do 
>not think so)? 
>because we have just one object in the memory. 
>what i need to understand what is going to happen when we send more than 
>request in the same time to 
>a servlet on the server?what is happening behind the scene? 


  Return to Index