aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Thread for a request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Thread for a request" Watch "Thread for a request" New topic
Author

Thread for a request

Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 355

From HFSJSP, 2e, chapter 4:
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() method, passing the request and response objects as arguments.

What's the relationship between the request and the allocated thread? A thread ( in small case ) is a virtual CPU with code and data to work. In the above statement, what are the code and data?
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

there is always(except in case of SingleThreadModel interface) single instance of servlet running. for each request , a new thread is created and allocated to serve that request. this thread or as you say piece of execution/cpu cycle executes service(request, response) which in turn dispatches the request to one of doGet or doPost http method. so basically the code on which thread operates is one in service, doGet/doPost method. the data for thread is any local variables you might have defined in your servlet.
 
Consider Paul's rocket mass heater.
 
subject: Thread for a request