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
This commit is contained in:
parent
c5131c62c9
commit
86ac6922fc
|
@ -27,8 +27,8 @@ package org.apache.http.impl.conn;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.http.annotation.NotThreadSafe;
|
import org.apache.http.annotation.NotThreadSafe;
|
||||||
|
@ -118,11 +118,10 @@ public class IdleConnectionHandler {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Checking for connections, idle timeout: " + idleTimeout);
|
log.debug("Checking for connections, idle timeout: " + idleTimeout);
|
||||||
}
|
}
|
||||||
Iterator<HttpConnection> connectionIter = connectionToTimes.keySet().iterator();
|
|
||||||
|
for (Entry<HttpConnection, TimeValues> entry : connectionToTimes.entrySet()) {
|
||||||
while (connectionIter.hasNext()) {
|
HttpConnection conn = entry.getKey();
|
||||||
HttpConnection conn = connectionIter.next();
|
TimeValues times = entry.getValue();
|
||||||
TimeValues times = connectionToTimes.get(conn);
|
|
||||||
long connectionTime = times.timeAdded;
|
long connectionTime = times.timeAdded;
|
||||||
if (connectionTime <= idleTimeout) {
|
if (connectionTime <= idleTimeout) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
|
@ -143,13 +142,10 @@ public class IdleConnectionHandler {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Checking for expired connections, now: " + now);
|
log.debug("Checking for expired connections, now: " + now);
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<HttpConnection> connectionIter =
|
for (Entry<HttpConnection, TimeValues> entry : connectionToTimes.entrySet()) {
|
||||||
connectionToTimes.keySet().iterator();
|
HttpConnection conn = entry.getKey();
|
||||||
|
TimeValues times = entry.getValue();
|
||||||
while (connectionIter.hasNext()) {
|
|
||||||
HttpConnection conn = connectionIter.next();
|
|
||||||
TimeValues times = connectionToTimes.get(conn);
|
|
||||||
if(times.timeExpires <= now) {
|
if(times.timeExpires <= now) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Closing connection, expired @: " + times.timeExpires);
|
log.debug("Closing connection, expired @: " + times.timeExpires);
|
||||||
|
@ -160,7 +156,7 @@ public class IdleConnectionHandler {
|
||||||
log.debug("I/O error closing connection", ex);
|
log.debug("I/O error closing connection", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TimeValues {
|
private static class TimeValues {
|
||||||
|
|
Loading…
Reference in New Issue