From 66c501639450e9acededcfa72f3e73daf2316633 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Tue, 22 Mar 2016 19:28:09 +0000 Subject: [PATCH] HTTPCLIENT-1730: added #setValidateAfterInactivity to HttpClientBuilder git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1736237 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/impl/sync/HttpClientBuilder.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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); }