*
The moose likes Servlets and the fly likes How servlet process multiple request. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How servlet process multiple request." Watch "How servlet process multiple request." New topic
Author

How servlet process multiple request.

vikram Kesav
Ranch Hand

Joined: Jul 11, 2008
Posts: 69
Hello Ranchers,

I am having confusion here --- like how servlet instance process multiple request as only one instance has been created during request processing.

Okay but more confusion is about SingleThreadedModel markup interface, How it makes servlet thread safe.

I have not found clear understanding from any tutorial, so please explain me.

Thanks in advance.
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 684


Hi,

As we know that servlet have no main() method so servlet need help to invoke the servlet. So another program invoke servlet for processing request of user.
So, when first request comes tomcat load servlet into container and load to servlet. Now container create thread for one request. Now at that time if another request comes container user that loaded servlet and create another thread for handle that new request. So container create new thread for each request and not create and load new servlet instance.

Now about thread safe i think servlets are not thread safe only instance variable of servlet are thread safe.



Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
vikram Kesav
Ranch Hand

Joined: Jul 11, 2008
Posts: 69
Thank you Nishan for sharing your knowledge with me.

I am agree with you that only one instance will get created in servlet container but still i need answer of my question that how container create threads of servlet and what method or instance has been shared beetween threads.

And about thread safe - we can make servlet thread save by implementing SingleThreadModel interface but how it handle internally ...i don't know...So Ranchers please help me and solve my confusion.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41108
    
  45
about SingleThreadedModel markup interface, How it makes servlet thread safe.

It doesn't. By implementing that interface the developer is telling the servlet container "this servlet is NOT thread-safe", so that the container will only run this servlet in a single thread at any given time. But that is not sufficient to make the web app thread-safe (there are other ways of making it thread-unsafe besides running a particular servlets in multiple threads simultaneously).

we can make servlet thread save by implementing SingleThreadModel interface

No, see above.

Now about thread safe i think servlets are not thread safe only instance variable of servlet are thread safe.

No. There are many ways of making a servlet not thread-safe; using instance variables can be one of them. But it's certainly possible to make servlets thread-safe.


Ping & DNS - my free Android networking tools app
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
how container create threads of servlet and what method or instance has been shared beetween threads.


Getting your head wrapped around the servlet life cycle after only working with single-user/single instance desktop applications takes a bit of work.

A google search for "servlet life cycle" will find resources for you.

Bill
Kumar Kamlesh
Greenhorn

Joined: May 10, 2009
Posts: 15
how container create threads of servlet and what method or instance has been shared beetween threads.


Servlet typically handles multiple requests by creating threads of service method.

- Kamlesh
vikram Kesav
Ranch Hand

Joined: Jul 11, 2008
Posts: 69
Thanks for all your energies....

now i have got little idea of that but i am still confussed as i would like to know the complete process of servlet container over servlet processing in the simplest term.

Can any one share any tutorial where i can get the same.

Thanks.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
would like to know the complete process of servlet container over servlet processing in the simplest term.


IF you had followed my advice and done a search for "servlet life cycle" you would already have the resources you need.

Bill
vikram Kesav
Ranch Hand

Joined: Jul 11, 2008
Posts: 69
Yes it really works!!!

I found answer of my question from below site-

http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets4.html

Thanks alot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How servlet process multiple request.
 
Similar Threads
member variables in servlet
Whether HTTPServlet Extends Thread or Not?
init()
Controlling servlet instances
How Servlet works?