Forums Register Login

How servlet process multiple request.

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send

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.

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
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
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 11149 times.
Similar Threads
Controlling servlet instances
Whether HTTPServlet Extends Thread or Not?
init()
member variables in servlet
How Servlet works?
Connection Pooling
SingleThreadModel
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:55:38.