diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java index 49ea06677..6e847ce2d 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java @@ -213,6 +213,7 @@ public class HttpClientBuilder { private long connTimeToLive = -1; private TimeUnit connTimeToLiveTimeUnit = TimeUnit.MILLISECONDS; + private int validateAfterInactivity = 2000; private List closeables; @@ -352,6 +353,23 @@ public class HttpClientBuilder { return this; } + /** + * Sets period after inactivity in milliseconds after which persistent + * connections must be checked to ensure they are still valid. + *

+ * Please note this value can be overridden by the {@link #setConnectionManager( + *HttpClientConnectionManager)} method. + *

+ * + * @see org.apache.hc.core5.http.io.HttpClientConnection#isStale() + * + * @since 5.0 + */ + public final HttpClientBuilder setValidateAfterInactivity(final int validateAfterInactivity) { + this.validateAfterInactivity = validateAfterInactivity; + return this; + } + /** * Assigns {@link HttpClientConnectionManager} instance. */ @@ -923,6 +941,7 @@ public class HttpClientBuilder { dnsResolver, connTimeToLive, connTimeToLiveTimeUnit != null ? connTimeToLiveTimeUnit : TimeUnit.MILLISECONDS); + poolingmgr.setValidateAfterInactivity(this.validateAfterInactivity); if (defaultSocketConfig != null) { poolingmgr.setDefaultSocketConfig(defaultSocketConfig); }