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
This commit is contained in:
Roland Weber 2007-02-17 17:49:06 +00:00
parent 12d50dda30
commit 486dd14981
1 changed files with 14 additions and 6 deletions

View File

@ -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<connManagers.length; i++) {
if (connManagers[i] != null)
connManagers[i].shutdown();
}
}