From 486dd14981e9136949f3a712db9e51d163f78dc7 Mon Sep 17 00:00:00 2001 From: Roland Weber Date: Sat, 17 Feb 2007 17:49:06 +0000 Subject: [PATCH] applied shutdownAll() part of HTTPCLIENT-625 git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@508782 13f79535-47bb-0310-9956-ffa450edef68 --- .../conn/ThreadSafeClientConnManager.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java b/src/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java index f63e5ed97..5478a51ac 100644 --- a/src/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java +++ b/src/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java @@ -405,12 +405,20 @@ public class ThreadSafeClientConnManager synchronized (REFERENCE_TO_CONNECTION_SOURCE) { // shutdown all connection managers synchronized (ALL_CONNECTION_MANAGERS) { - Iterator connIter = ALL_CONNECTION_MANAGERS.keySet().iterator(); - while (connIter.hasNext()) { - ThreadSafeClientConnManager connManager = - (ThreadSafeClientConnManager) 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