• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread for a request

 
Faisal Ahmad
Ranch Hand
Posts: 355
Chrome Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic