From 86ac6922fc870ebfb29f6f821c7ea3a35f520d72 Mon Sep 17 00:00:00 2001 From: Sebastian Bazley Date: Sat, 16 Jan 2010 14:11:50 +0000 Subject: [PATCH] HTTPCLIENT-906 Minor performance improvement to IdleConnectionHandler Replace keySet() + get() with entrySet() git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@899957 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/impl/conn/IdleConnectionHandler.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java b/httpclient/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java index 479992bbd..7538e03b7 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java @@ -27,8 +27,8 @@ package org.apache.http.impl.conn; import java.io.IOException; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; import java.util.concurrent.TimeUnit; import org.apache.http.annotation.NotThreadSafe; @@ -118,11 +118,10 @@ public class IdleConnectionHandler { if (log.isDebugEnabled()) { log.debug("Checking for connections, idle timeout: " + idleTimeout); } - Iterator connectionIter = connectionToTimes.keySet().iterator(); - - while (connectionIter.hasNext()) { - HttpConnection conn = connectionIter.next(); - TimeValues times = connectionToTimes.get(conn); + + for (Entry entry : connectionToTimes.entrySet()) { + HttpConnection conn = entry.getKey(); + TimeValues times = entry.getValue(); long connectionTime = times.timeAdded; if (connectionTime <= idleTimeout) { if (log.isDebugEnabled()) { @@ -143,13 +142,10 @@ public class IdleConnectionHandler { if (log.isDebugEnabled()) { log.debug("Checking for expired connections, now: " + now); } - - Iterator connectionIter = - connectionToTimes.keySet().iterator(); - - while (connectionIter.hasNext()) { - HttpConnection conn = connectionIter.next(); - TimeValues times = connectionToTimes.get(conn); + + for (Entry entry : connectionToTimes.entrySet()) { + HttpConnection conn = entry.getKey(); + TimeValues times = entry.getValue(); if(times.timeExpires <= now) { if (log.isDebugEnabled()) { log.debug("Closing connection, expired @: " + times.timeExpires); @@ -160,7 +156,7 @@ public class IdleConnectionHandler { log.debug("I/O error closing connection", ex); } } - } + } } private static class TimeValues {