Author: rolandw Date: Sun Feb 4 03:13:34 2007 New Revision: 503386 URL: http://svn.apache.org/viewvc?view=rev&rev=503386 Log: HTTPCLIENT-625
Modified: jakarta/commons/proper/httpclient/trunk/release_notes.txt jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java Modified: jakarta/commons/proper/httpclient/trunk/release_notes.txt URL: http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/release_notes.txt?view=diff&rev=503386&r1=503385&r2=503386 ============================================================================== --- jakarta/commons/proper/httpclient/trunk/release_notes.txt (original) +++ jakarta/commons/proper/httpclient/trunk/release_notes.txt Sun Feb 4 03:13:34 2007 @@ -1,4 +1,7 @@ -Changes since Release 3.1 Beta 1: +Changes since Release 3.1 Beta 1: + +* [HTTPCLIENT-625] - revised shutdown of MultiThreadedHttpConnectionManager + Contributed by Roland Weber <rolandw at apache.org> * [HTTPCLIENT-622] - Leak in MultiThreadedHttpConnectionManager.ConnectionPool.mapHosts Contributed by Michael Becke <mbecke at apache.org> and Ortwin Glueck <oglueck at apache.org> @@ -6,8 +9,8 @@ * [HTTPCLIENT-612] - FileRequestEntity now always closes the input file. Contributed by Sebastian Bazley <sebb at apache.org> -* [HTTPCLIENT-616] - HttpMethodDirector.executeWithRetry method fixed to close the - underlying connection if a RuntimeException is thrown +* [HTTPCLIENT-616] - HttpMethodDirector.executeWithRetry method fixed to close + the underlying connection if a RuntimeException is thrown Contributed by Jason Bird * [HTTPCLIENT-606] - Added a HTTP method level parameter for URI charset Modified: jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java?view=diff&rev=503386&r1=503385&r2=503386 ============================================================================== --- jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java (original) +++ jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java Sun Feb 4 03:13:34 2007 @@ -113,12 +113,20 @@ synchronized (REFERENCE_TO_CONNECTION_SOURCE) { // shutdown all connection managers synchronized (ALL_CONNECTION_MANAGERS) { - Iterator connIter = ALL_CONNECTION_MANAGERS.keySet().iterator(); - while (connIter.hasNext()) { - MultiThreadedHttpConnectionManager connManager = - (MultiThreadedHttpConnectionManager) connIter.next(); - connIter.remove(); - connManager.shutdown(); + // Don't use an iterator here. Iterators on WeakHashMap can + // get ConcurrentModificationException on garbage collection. + MultiThreadedHttpConnectionManager[] + connManagers = (MultiThreadedHttpConnectionManager[]) + ALL_CONNECTION_MANAGERS.keySet().toArray( + new MultiThreadedHttpConnectionManager + [ALL_CONNECTION_MANAGERS.size()] + ); + + // The map may shrink after size() is called, or some entry + // may get GCed while the array is built, so expect null. + for (int i=0; i<connManagers.length; i++) { + if (connManagers[i] != null) + connManagers[i].shutdown(); } } @@ -237,7 +245,7 @@ /** Connection Pool */ private ConnectionPool connectionPool; - private boolean shutdown = false; + private volatile boolean shutdown = false; // ----------------------------------------------------------- Constructors @@ -259,7 +267,7 @@ * Shuts down the connection manager and releases all resources. All connections associated * with this class will be closed and released. * - * <p>The connection manager can no longer be used once shutdown. + * <p>The connection manager can no longer be used once shut down. * * <p>Calling this method more than once will have no effect. */ @@ -1033,7 +1041,7 @@ */ private static class ReferenceQueueThread extends Thread { - private boolean shutdown = false; + private volatile boolean shutdown = false; /** * Create an instance and make this a daemon thread. @@ -1045,6 +1053,7 @@ public void shutdown() { this.shutdown = true; + this.interrupt(); } /** @@ -1078,10 +1087,8 @@ public void run() { while (!shutdown) { try { - // remove the next reference and process it, a timeout - // is used so that the thread does not block indefinitely - // and therefore keep the thread from shutting down - Reference ref = REFERENCE_QUEUE.remove(1000); + // remove the next reference and process it + Reference ref = REFERENCE_QUEUE.remove(); if (ref != null) { handleReference(ref); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]