tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Juha Laiho <>
Subject Re: Threads in tomcat application.
Date Sun, 02 Sep 2007 19:26:33 GMT
Manivannan Palanichamy wrote:
> I need to design a web application that may use threads. Thats, the web
> application might have to read some 200 files from network. In order to
> speed up the process, I've decided to use threads/thread pooling. But,
> however I know it is not a good practice to use threads in a web/server
> application... Just want to know whether this will be a great impact in
> future.. Otherwise, do you suggest any alternative design for the above
> problem? Looking forward a quick reply :-)

This might be a correct place for multithreading: slowness is somewhere
else than actual processing load of the server (and most probably
implementing this with multithreading will not saturate the network
connection of the server for extended times, either). So, one danger
of multithreading (as with all multiprocessing) is that your application
can starve itself of resources, and make the server spend most of its
time switching from one task to another (trashing). Tune the pool small
enough to avoid this danger, but large enough to benefit of being able to
interleave several tasks.

That being said, a long-running server application (such as a webapp running
under Tomcat) needs different care with threads than a end-user application.

Potential issues you'll need to handle in your code:
- threads may get stuck while attempting to do something (esp. when you're
  reading data over network); make sure your code doesn't have any place
  where a thread may hang for an indefinite time; make sure each thread
  will terminate with predetermined results for each possible case
  (otherwise your code will leak threads, and through that, memory)
- make sure all threads teminate also when the application is undeployed
  (for whatever reason, such as deploying a newer version of the webapp;
  again, this is to avoid memory/thread leaks)
- if possible, make all threads as "daemon threads" - so that a hung
  thread will not prevent Tomcat Java process from exiting

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message