• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it the container or the Thread??

 
Mayank Mishra
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kathy and Bryan mention in their book HFS&J that the service() method in servlets is called by the container.How is it done?I believed that the container just created a thread and "started" it and then it was the run() method of the thread that had a call to service() which in turn would call doXXX().
 
Bryan Basham
author
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Mayank,

You answered your own question. The container is all of the code that makes up what you just described (plus a lot lot more).

-Bryan
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe you're dead on, Mayank. However, I believe some containers will utilize a thread pool, rather than always creating a new thread. So, it may be possible that the container will reuse a thread, rather than making a new one for each request. Regardless, the thread assigned to the request is responsible for invoking the service() method of the HttpServlet.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether there is a pool for Servlet instances, and how many instances a container kept is vendor specific.

But at least, IBM WAS does provide a Servlet pool for holding several instances to serve simultaneous requests. I do believe this will the majority of the well-known containers.

Nick
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic