This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Here is what i know...
Threads can be created by extending Thread class or by implementing Runnable.
In the first case, to set the thread in running state, we create a object of the class that extends the Thread class and call the start() which in turn calls the run().
In the second case, We create a thread object and give the thread the runnable class object. And we call the start() using the thread reference.
HFSJ wrote:The container finds the correct servlet based on the URL in the request, creates or allocates a thread for that request and calls the servlet's service() ,passing the req & res object as arguments
So how do the container create the thread,
If its the first case. then the servlet that i write does not extend thread class, then how is it done?
If it is the second case , then also my servlet is not implementing the runnable??
Could you explain how this is done...
Or am i missing something very badly???
I mean to find out .... what is the argument that thread is getting ??? a servlet object? or ....???
Suppose this is the container's code to start a new thread
When the servler receives a request, it will just create an instance of this class (i.e. ProcessRequest) with the servlet to be called and the request and response objects and then call start on the instance of this class. Now your servlet class doesn't need to implement Runnable or extend Thread. I don't know exactly what technique the container uses to call the service method, but it must be similar to the one above...