Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How servlet process multiple request.

 
vikram Kesav
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

 
vikram Kesav
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic