Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 19482 invoked from network); 19 Jul 2007 21:10:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Jul 2007 21:10:57 -0000 Received: (qmail 44579 invoked by uid 500); 19 Jul 2007 21:10:17 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 44559 invoked by uid 500); 19 Jul 2007 21:10:16 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 44544 invoked by uid 99); 19 Jul 2007 21:10:16 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Jul 2007 14:10:16 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (herse.apache.org: local policy) Received: from [63.240.77.83] (HELO sccrmhc13.comcast.net) (63.240.77.83) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Jul 2007 14:10:13 -0700 Received: from [10.10.10.78] (70-90-82-203-washingtondc-dc.hfc.comcastbusiness.net?[70.90.82.203]) by comcast.net (sccrmhc13) with ESMTP id <2007071921095201300a1djfe>; Thu, 19 Jul 2007 21:09:52 +0000 Message-ID: <469FD315.4000005@christopherschultz.net> Date: Thu, 19 Jul 2007 17:09:41 -0400 From: Christopher Schultz User-Agent: Thunderbird 2.0.0.4 (Windows/20070604) MIME-Version: 1.0 To: Tomcat Users List Subject: Re: Interrupting tomcat threads. References: <11697335.post@talk.nabble.com> In-Reply-To: <11697335.post@talk.nabble.com> X-Enigmail-Version: 0.95.2 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org -----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