diff --git a/module-client/src/main/java/org/apache/http/client/ClientResponseHandler.java b/module-client/src/main/java/org/apache/http/client/ClientResponseHandler.java index 4179d7b2d..37acf04df 100644 --- a/module-client/src/main/java/org/apache/http/client/ClientResponseHandler.java +++ b/module-client/src/main/java/org/apache/http/client/ClientResponseHandler.java @@ -36,7 +36,7 @@ import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; /** - * Handler that incapsulates the process of generating a response object + * Handler that encapsulates the process of generating a response object * from a {@link HttpResponse}. * * @author Oleg Kalnichevski diff --git a/module-client/src/main/java/org/apache/http/conn/ManagedClientConnection.java b/module-client/src/main/java/org/apache/http/conn/ManagedClientConnection.java index bb0106203..1835e4bdc 100644 --- a/module-client/src/main/java/org/apache/http/conn/ManagedClientConnection.java +++ b/module-client/src/main/java/org/apache/http/conn/ManagedClientConnection.java @@ -249,9 +249,12 @@ public interface ManagedClientConnection extends ; /** - * Sets the duration that this connection can remain idle - * before it is reused. - * The connection should not be used again if this time elapses. + * Sets the duration that this connection can remain idle before it is + * reused. The connection should not be used again if this time elapses. The + * idle duration must be reset after each request sent over this connection. + * The elapsed time starts counting when the connection is released, which + * is typically after the headers (and any response body, if present) is + * fully consumed. */ void setIdleDuration(long duration, TimeUnit unit); diff --git a/module-client/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java b/module-client/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java index ae0099c00..c9486e3a5 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java @@ -99,9 +99,6 @@ public abstract class AbstractClientConnAdapter /** True if the connection has been aborted. */ private volatile boolean aborted; - /** The last time this processed incoming headers. */ - private volatile long lastHeadersRead; - /** The duration this is valid for while idle (in ms). */ private volatile long duration; @@ -259,8 +256,6 @@ public abstract class AbstractClientConnAdapter assertValid(conn); unmarkReusable(); - duration = Long.MAX_VALUE; // Reset duration per request. - lastHeadersRead = System.currentTimeMillis(); return conn.receiveResponseHeader(); } @@ -361,39 +356,14 @@ public abstract class AbstractClientConnAdapter if(duration > 0) { this.duration = unit.toMillis(duration); } else { - this.duration = Long.MAX_VALUE; - } - } - - /** - * Returns the amount of time remaining that this connection - * can be reused. If negative, the connection should not - * be reused. If Long.MAX_VALUE, there is no suggested - * duration. - * - * The remaining time is the elapsed time between now, - * the time the last headers were processed, and the duration - * given from {@link #setIdleDuration(long, TimeUnit)}. - */ - protected long getRemainingIdleDuration() { - if(duration == Long.MAX_VALUE) { - return Long.MAX_VALUE; - } else { - long elapsedAlready = System.currentTimeMillis() - lastHeadersRead; - return duration - elapsedAlready; + this.duration = -1; } } // non-javadoc, see interface ConnectionReleaseTrigger public void releaseConnection() { if (connManager != null) { - long remainingTime = getRemainingIdleDuration(); - if(remainingTime <= 0) { - unmarkReusable(); - } else if(remainingTime == Long.MAX_VALUE) { - remainingTime = -1; - } - connManager.releaseConnection(this, remainingTime, TimeUnit.MILLISECONDS); + connManager.releaseConnection(this, duration, TimeUnit.MILLISECONDS); } }