Saturday, March 14, 2009

Is it true that servlet containers service each request by creating a new

Question :Is it true that servlet containers service each request by creating a new
thread? If that is true, how does a container handle a sudden dramatic
surge in incoming requests without significant performance
degradation? (Servlets)


Answer :The implementation depends on the Servlet engine. For each request
generally, a new Thread is created. But to give performance boost, most
containers, create and maintain a thread pool at the server startup time.
To service a request, they simply borrow a thread from the pool and when
they are done, return it to the pool.
For this thread pool, upper bound and lower bound is maintained. Upper
bound prevents the resource exhaustion problem associated with unlimited
thread allocation. The lower bound can instruct the pool not to keep too
many idle threads, freeing them if needed.

No comments: