tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Interrupting tomcat threads.
Date Thu, 19 Jul 2007 21:09:41 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kief,

keif wrote:
> I'd like to find a way to stop the first request from processing when a
> second one is recieved. So the first request comes in and the container
> starts a thread to process it. Then the second request comes in and before
> it is processed, I want it to cancel processing the first request.

For the record, I think this is a terrible idea. Why would you want to
stop an existing thread when a new one comes in? (I assume you mean that
you want to cancel an already-running thread /for a given user/ if a
second one comes in).

> Can this be accomplished by interrupting threads? Should I spawn new threads
> for such processing and manage them instead of working with threads given by
> the container?

I think you can do this (but I still don't understand why you'd want
to). You could do something like this:

1. Writer a filter that stores the currently-running thread into the
user's session, then chains to the next filter, then removes the thread
from the session. (Remember to watch exception handling AND check to
make sure that it's the same thread you stored before you remove it!)

2. Modify the filter in #1 to check for an existing thread in the
session. If such a thread exists, grab it, interrupt() it, and then
proceed to store/chain/remove the thread.

A few notes:

1. If you are running Tomcat under a SecurityManager (or maybe even if
you're not!), you might not be able to call interrupt() on another
thread. Beware!

2. Tomcat might misbehave if you call interrupt() on a request
processing thread. Beware!

3. It might be perfectly reasonable for two threads to be executing at
once on behalf of a legitimate client. For instance, the browser decides
to launch two separate requests to request page components instead of
using a single keep-alive connection. Or, you might have some AJAX thing
going on while the main page is loading (or re-loading). In these cases,
you're going to get all kinds of weird errors and your users will be
unhappy.

Again... why do you want to do this?

- -chris

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

iD8DBQFGn9MV9CaO5/Lv0PARAh0JAJ9B2VtmQDhGtV5ZQj/PhefLhTZnvQCghh2z
gXjGUHD6Ts3KJRcTjp46QJE=
=D9HM
-----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