HTTPCLIENT-1826: HttpAsyncClientBuilder to accept ThreadFactory attribute
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1793762 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
index 0f9f81f..07699a7 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
@@ -34,6 +34,7 @@
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
+import java.util.concurrent.ThreadFactory;
import org.apache.hc.client5.http.ConnectionKeepAliveStrategy;
import org.apache.hc.client5.http.SchemePortResolver;
@@ -236,6 +237,8 @@
private boolean authCachingDisabled;
private boolean connectionStateDisabled;
+ private ThreadFactory threadFactory;
+
private List<Closeable> closeables;
public static HttpAsyncClientBuilder create() {
@@ -481,6 +484,14 @@
}
/**
+ * Assigns {@link ThreadFactory} instance.
+ */
+ public final HttpAsyncClientBuilder setThreadFactory(final ThreadFactory threadFactory) {
+ this.threadFactory = threadFactory;
+ return this;
+ }
+
+ /**
* Assigns {@code User-Agent} value.
*/
public final HttpAsyncClientBuilder setUserAgent(final String userAgent) {
@@ -875,7 +886,7 @@
ioReactor = new DefaultConnectingIOReactor(
ioEventHandlerFactory,
ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT,
- new DefaultThreadFactory("httpclient-dispatch", true),
+ threadFactory != null ? threadFactory : new DefaultThreadFactory("httpclient-dispatch", true),
new Callback<IOSession>() {
@Override
@@ -944,7 +955,7 @@
ioReactor,
execChain,
pushConsumerRegistry,
- new DefaultThreadFactory("httpclient-main", true),
+ threadFactory != null ? threadFactory : new DefaultThreadFactory("httpclient-main", true),
connManagerCopy,
routePlannerCopy,
versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE,