aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes how thread are created by the container Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "how thread are created by the container" Watch "how thread are created by the container" New topic
Author

how thread are created by the container

Sony Agrawal
Ranch Hand

Joined: Oct 04, 2009
Posts: 143
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 ....???
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Sony Agrawal
Ranch Hand

Joined: Oct 04, 2009
Posts: 143
Ankit Garg wrote:When the servler receives a request, ..

I think you meant container...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

sony agrwal wrote:
Ankit Garg wrote:When the servler receives a request, ..

I think you meant container...

Yup
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how thread are created by the container