tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Increasing memory problem (i hope this helps)
Date Tue, 28 Nov 2000 20:38:53 GMT
See below.

Saurabh Shukla wrote:

> >could you tell me more about the thread pooling, please? Where do I get
> some
> >information? How does Tomcat handle the requests?
> >Thank you.
> >Kai
> I hope this helps.
> Tomcat is a multi-threaded servlet container, this means that the requests
> needs to be executed by some thread, when a new requests arrives a new
> thread
> starts and serves the request. This is very problmatic coz' of this it is
> hard
> to limit the resource consumptio, i.e if 300 requests arrive concurrently
> tomcat will open 300 threads and serve them, this causes tomcat to allocate
> more resources(CPU, memory,..) than it should and leads to low performance
> and
> crashes.(for that matter memory problems with Oracle were coz' of this).
> THE SOLUTION: Having a thread pool, instead of allocating new threadsl
> whenvever they need a thread they ask for it from the pool and and when they
> are done
> the thread is returned to the pool. Thread management techniques such as:
> 1) Keeping threads open and reusing them over and over again, this saves
> trouble associated with creating and destructing threads continuously.
> 2) setting an upper bound on the number of concurrent threads used, this
> solves the resource allocation problem.
> Shuklix
> ----------------------------------------------------------------------------
> ----
> Ps: This is a excerpt from a write up which i had read,  had kept this
>     a small write up for my reference.   Sorry author for not being able to
> give
>     you due credit.
> ----------------------------------------------------------------------------

To amplify this explanation slightly:  Tomcat allows you to configure the use of
a thread pool, and limit the maximum number of simultaneous requests by limiting
the maximum number of threads that are allowed in the pool.  The details of how
to do this (in server.xml) depend on which version of Tomcat you are talking

It actually makes no functional difference to your applications whether Tomcat
is using a thread pool or creating threads on the fly -- the only differences
will be performance related.  In particular, you can limit the total number of
threads even if you are creating them on the fly, by simply maintaining a
reference count of how many active threads there are, and refusing to create one
if you are at the maximum already.

But, that all being said, threads are the servlet container's problem to
manage.  The application developer, thankfully, needs to worry only about their
application (including the fact that a particular servlet can be accessed by
more than one thread at the same time -- but you don't have to worry about *how*
that happens).

Craig McClanahan

View raw message