• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

allocating a thread to a servlet request

 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4116
195
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Bill
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok ... so that means it is not completely destroyed and can be allocated to some other servlet request if need be ?
 
Amit Ghorpade
Bartender
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

container creates an instance of Thread class for each request.I think it willnt maintain a pool of threads
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic