tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Can servlets safely spawn threads?
Date Mon, 29 Jan 2007 14:20:46 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Danny,

David Delbecq wrote:
> 1) Your servlet must always take care to finish all Threads it has
> spawned. This mean when servlet gets unloaded, you must have provided a
> mecanism in your servlet to stop all running threads your servlet has
> created. Remaining Threads not handled by container can either cause
> tomcat to not stop when requested or prevent garbage collecting of
> webapp when reloading.

Consider using an existing thread pool component. It should have a
graceful shutdown capability already built into it. David is right: you
have to make sure to shut it down when appropriate.

> In general, try to avoid spawning your own thread.

I agree, which is why I recommend using a thread pool. Yes, you are
still technically spawning your own threads (the container will not do
it for you), but the point is that you will not be spawning a thread for
each request.

Set up your thread pool to have a "reasonable" number of threads for
your application. You do not want to have loads of users submit jobs
that will each spawn a new thread. If you run out of threads in the
thread pool, you simply tell the user to come back later. Management of
this type of resource is essential to maintaining a stable and useful
system.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFvgK+9CaO5/Lv0PARAoIFAJ45DgOyFV9qxS2e+Qt9uHNTtkWpywCdHbnq
pltJVjDsmhZMg0143155k7M=
=pbEp
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message