You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Harry Mantheakis <ha...@mantheakis.freeserve.co.uk> on 2004/02/16 21:57:24 UTC

Re: How Servlets work?

Hello

> how the webserver handles more than one
> request at the same time.

The answer is: by invoking the servlet's service method in a new thread for
each new request to that servlet.

Think of any Java object, instantiated once - a public method in that object
can be called any number of times, concurrently. Each invocation will be
processed in a new thread.

Synchronisation is an issue only when the method in question uses references
to other objects. If the method only works with local variables, there is no
synchronisation problem!

So, in a nutshell: with servlets, make sure the service method only uses
local variables, including, of course, those two most useful parameters, the
request and the response objects.

Regards

Harry Mantheakis
London, UK


> Hi all,
> 
> may be not the right place to ask this question. Hope somebody is kind
> enough to clarify this doubt of mine.
> 
> i understand, in  a servlet, if i need any code to be thread safe, then
> i shud put that code inside a synhronized block
> or declared the entire method as synchronized. if my understanding is
> right, only instance of our serlvet class is being
> created. in that case how the webserver handles more than one request at
> the same time. i mean, is some queuing structure
> being followed, (i am tempted to believe it is not multithreaded)?
> 
> Could anybody clarify this doubt of mine or atleast point out some ref.
> material for this.
> 
> Thanks
> R.Saravanan
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: How Servlets work?

Posted by saravanan <sa...@naturesoft.net>.
Thanks a lot Harry. Thank you so much.

Saravanan
Harry Mantheakis wrote:

>Hello
>
>  
>
>>how the webserver handles more than one
>>request at the same time.
>>    
>>
>
>The answer is: by invoking the servlet's service method in a new thread for
>each new request to that servlet.
>
>Think of any Java object, instantiated once - a public method in that object
>can be called any number of times, concurrently. Each invocation will be
>processed in a new thread.
>
>Synchronisation is an issue only when the method in question uses references
>to other objects. If the method only works with local variables, there is no
>synchronisation problem!
>
>So, in a nutshell: with servlets, make sure the service method only uses
>local variables, including, of course, those two most useful parameters, the
>request and the response objects.
>
>Regards
>
>Harry Mantheakis
>London, UK
>
>
>  
>
>>Hi all,
>>
>>may be not the right place to ask this question. Hope somebody is kind
>>enough to clarify this doubt of mine.
>>
>>i understand, in  a servlet, if i need any code to be thread safe, then
>>i shud put that code inside a synhronized block
>>or declared the entire method as synchronized. if my understanding is
>>right, only instance of our serlvet class is being
>>created. in that case how the webserver handles more than one request at
>>the same time. i mean, is some queuing structure
>>being followed, (i am tempted to believe it is not multithreaded)?
>>
>>Could anybody clarify this doubt of mine or atleast point out some ref.
>>material for this.
>>
>>Thanks
>>R.Saravanan
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org