This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
In Head First Servlets and JSP it is emphasized again and again that ...
the container starts a new thread or allocates a thread from the pool
is their any difference between the two ... ???
if it is ... then does the pool contains a limited number of threads or so ???
moreover, as after the service method completes the thread is destroyed and the request and response objects are eligible for garbage collection ... then doesn't it effects the number of threads in the pool ???
i personally think ... it's just the way to teach saying these two things but just want's to clarify ... hope no one minds
Lalit Mehra wrote:moreover, as after the service method completes the thread is destroyed and the request and response objects are eligible for garbage collection ... then doesn't it effects the number of threads in the pool ???
Why do you think it can affect the thread?
A thread which has completed the life-cycle of a servlet can be detached from that servlet and pooled for a later execution on another servlet. The way how it is done is up to the container provider and it's not defined in the JavaEE specification. A book, which is generically targeting on the Servlet and JSP technologies cannot explain you the underneath techniques of various container providers - there are many.
as after the service method completes the thread is destroyed and the request and response objects are eligible for garbage collection ..
No - thats the whole point of Thread pools, the Thread is available for the next request. HttpRequest and response objects may also be managed in a pool - that is up to the implementor. A google search for Java Thread Pool Implementation turned up lots of examples you could study.
Yep. That is why the term 'pool' is used. As said above the underlying implementation varies and these threads are supported by operating system threads which in turn work on hardware threads (if present).
srinu polam wrote:container creates an instance of Thread class for each request.I think it willnt maintain a pool of threads
As was mentioned before, that is up to the servlet container. But object creation in general has become much cheaper over the years as JVMs have become smarter, and pooling of objects for reuse has consequently become less important (network connections -like to a DB- are an exception to this). So it's possible that modern containers no longer use thread pools.