Return-Path: Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: (qmail 92794 invoked from network); 3 Sep 2010 05:28:09 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 3 Sep 2010 05:28:09 -0000 Received: (qmail 58202 invoked by uid 500); 3 Sep 2010 05:28:08 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 57765 invoked by uid 500); 3 Sep 2010 05:28:05 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 57756 invoked by uid 99); 3 Sep 2010 05:28:04 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Sep 2010 05:28:04 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Sep 2010 05:27:46 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DA3ED238890A; Fri, 3 Sep 2010 05:27:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r992211 - /tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Date: Fri, 03 Sep 2010 05:27:24 -0000 To: dev@tomcat.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100903052724.DA3ED238890A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Fri Sep 3 05:27:24 2010 New Revision: 992211 URL: http://svn.apache.org/viewvc?rev=992211&view=rev Log: Join poller and sendfile threads on destroy. This requires to change the Poller and Sendile to Thread instead Runnable for simplicity. Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=992211&r1=992210&r2=992211&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Fri Sep 3 05:27:24 2010 @@ -542,10 +542,10 @@ public class AprEndpoint extends Abstrac for (int i = 0; i < pollerThreadCount; i++) { pollers[i] = new Poller(false); pollers[i].init(); - Thread pollerThread = new Thread(pollers[i], getName() + "-Poller-" + i); - pollerThread.setPriority(threadPriority); - pollerThread.setDaemon(true); - pollerThread.start(); + pollers[i].setName(getName() + "-Poller-" + i); + pollers[i].setPriority(threadPriority); + pollers[i].setDaemon(true); + pollers[i].start(); } // Start comet poller threads @@ -553,10 +553,10 @@ public class AprEndpoint extends Abstrac for (int i = 0; i < pollerThreadCount; i++) { cometPollers[i] = new Poller(true); cometPollers[i].init(); - Thread pollerThread = new Thread(cometPollers[i], getName() + "-CometPoller-" + i); - pollerThread.setPriority(threadPriority); - pollerThread.setDaemon(true); - pollerThread.start(); + cometPollers[i].setName(getName() + "-CometPoller-" + i); + cometPollers[i].setPriority(threadPriority); + cometPollers[i].setDaemon(true); + cometPollers[i].start(); } // Start sendfile threads @@ -565,10 +565,10 @@ public class AprEndpoint extends Abstrac for (int i = 0; i < sendfileThreadCount; i++) { sendfiles[i] = new Sendfile(); sendfiles[i].init(); - Thread sendfileThread = new Thread(sendfiles[i], getName() + "-Sendfile-" + i); - sendfileThread.setPriority(threadPriority); - sendfileThread.setDaemon(true); - sendfileThread.start(); + sendfiles[i].setName(getName() + "-Sendfile-" + i); + sendfiles[i].setPriority(threadPriority); + sendfiles[i].setDaemon(true); + sendfiles[i].start(); } } @@ -576,10 +576,10 @@ public class AprEndpoint extends Abstrac acceptors = new Acceptor[acceptorThreadCount]; for (int i = 0; i < acceptorThreadCount; i++) { acceptors[i] = new Acceptor(); - Thread acceptorThread = new Thread(acceptors[i], getName() + "-Acceptor-" + i); - acceptorThread.setPriority(threadPriority); - acceptorThread.setDaemon(getDaemon()); - acceptorThread.start(); + acceptors[i].setName(getName() + "-Acceptor-" + i); + acceptors[i].setPriority(threadPriority); + acceptors[i].setDaemon(getDaemon()); + acceptors[i].start(); } } @@ -670,6 +670,16 @@ public class AprEndpoint extends Abstrac if (running) { running = false; unlockAccept(); + for (int i = 0; i < acceptors.length; i++) { + if (acceptors[i].isAlive()) { + try { + acceptors[i].interrupt(); + acceptors[i].join(); + } catch (InterruptedException e) { + // Ignore + } + } + } // Wait for polltime before doing anything, so that the poller threads // exit, otherwise parallel destruction of sockets which are still // in the poller can cause problems @@ -682,27 +692,36 @@ public class AprEndpoint extends Abstrac } for (int i = 0; i < pollers.length; i++) { pollers[i].destroy(); + try { + pollers[i].interrupt(); + pollers[i].join(); + } catch (InterruptedException e) { + // Ignore + } } pollers = null; for (int i = 0; i < cometPollers.length; i++) { cometPollers[i].destroy(); + try { + cometPollers[i].interrupt(); + cometPollers[i].join(); + } catch (InterruptedException e) { + // Ignore + } } cometPollers = null; if (useSendfile) { for (int i = 0; i < sendfiles.length; i++) { sendfiles[i].destroy(); + try { + sendfiles[i].interrupt(); + sendfiles[i].join(); + } catch (InterruptedException e) { + // Ignore + } } sendfiles = null; } - // Wait another polltime to make sure everything is shutdown else - // the JVM will crash when we terminate the APR library - try { - synchronized (this) { - this.wait(pollTime / 1000); - } - } catch (InterruptedException e) { - // Ignore - } } shutdownExecutor(); } @@ -892,7 +911,7 @@ public class AprEndpoint extends Abstrac /** * Server socket acceptor thread. */ - protected class Acceptor implements Runnable { + protected class Acceptor extends Thread { /** @@ -952,7 +971,7 @@ public class AprEndpoint extends Abstrac /** * Poller class. */ - public class Poller implements Runnable { + public class Poller extends Thread { protected long serverPollset = 0; protected long pool = 0; @@ -999,7 +1018,7 @@ public class AprEndpoint extends Abstrac /** * Destroy the poller. */ - protected void destroy() { + public void destroy() { // Close all sockets in the add queue for (int i = 0; i < addCount; i++) { if (comet) { @@ -1216,7 +1235,7 @@ public class AprEndpoint extends Abstrac /** * Sendfile class. */ - public class Sendfile implements Runnable { + public class Sendfile extends Thread { protected long sendfilePollset = 0; protected long pool = 0; @@ -1254,7 +1273,7 @@ public class AprEndpoint extends Abstrac /** * Destroy the poller. */ - protected void destroy() { + public void destroy() { // Close any socket remaining in the add queue addCount = 0; for (int i = (addS.size() - 1); i >= 0; i--) { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org