Two Laptop Bag*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Is it the container or the Thread?? 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 "Is it the container or the Thread??" Watch "Is it the container or the Thread??" New topic
Author

Is it the container or the Thread??

Mayank Mishra
Greenhorn

Joined: Oct 20, 2004
Posts: 5
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().


Mayank
Bryan Basham
author
Ranch Hand

Joined: Apr 30, 2001
Posts: 199
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

Joined: Dec 20, 2001
Posts: 3271
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.


SCJP Tipline, etc.
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
 
 
subject: Is it the container or the Thread??
 
Similar Threads
Each request runs in a separate thread?
Who calls the service() and how?
Servlets and Threading
How container Handle request
Threads