S e r v le t  C o n ta in e r
T h r e a d   P o o l
S e r v le t  A
S e r v le t  B
T h r e a d   1
T h r e a d   2
T h r e a d   n
                 in it( )
                 in it( )
a llo c a t e   t h r e a d
a llo c a te  th r e a d
                         s e r v ic e ( )
     rv i
     c e
    ( )
          r e le a s e   th r e a d
r e le a s e   th r e a d
a llo c a te  th r e a d
                         s e r v ic e ( )
r e le a s e   th r e a d
                         d e s tr o
    y (
     )                d e s tr o y ( )
Figure 4: Typical Servlet Container Implementation 
In this model, the Servlet Container creates a  Thread Pool  at start up time. A Thread Pool is a 
collection of threads. When a new request is received, one of the available threads is allocated 
to the request. The thread then runs the service() method of the servlet that maps to the 
request. The thread is returned to the Thread Pool afterwards, so it can be re used for another 
request. With this model, many requests can be handled simultaneously without the Servlet 
Container having to instantiate any new objects. The number of available threads in the Thread 
Pool is usually configurable, so performance can be optimized for the number of requests that 
an application usually receives over a certain time period. If all threads are in use, and another 
request is received, the synchronization capabilities of Java allow waiting for the next thread to 
become available. 
A new instance of a servlet is only created when the servlet is requested for the first time. The 
Servlet container makes sure that the servlet's initialization method init() has finished before the 
service() method is called. The servlet's service() method can be run many times, and can even 

Java Web Hosting Application Development Using Java Technologies Hosting

TotalRoute.net Business web hosting division of Vision Web Hosting Inc. All rights reserved.