Skip to content

Commit 8f7752d

Browse files
committed
- Rework previous fix.
- Switch from cached thread pool to fixed thread pool.
1 parent bf575f6 commit 8f7752d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ private AsyncHttpClientConfig(int maxTotalConnections,
157157
int spdyInitialWindowSize,
158158
int spdyMaxConcurrentStreams,
159159
boolean rfc6265CookieEncoding,
160-
boolean asyncConnectMode) {
160+
boolean asyncConnectMode,
161+
boolean managedApplicationThreadPool) {
161162

162163
this.maxTotalConnections = maxTotalConnections;
163164
this.maxConnectionPerHost = maxConnectionPerHost;
@@ -189,13 +190,8 @@ private AsyncHttpClientConfig(int maxTotalConnections,
189190
this.ioThreadMultiplier = ioThreadMultiplier;
190191
this.strict302Handling = strict302Handling;
191192
this.useRelativeURIsWithSSLProxies = useRelativeURIsWithSSLProxies;
192-
193-
if (applicationThreadPool == null) {
194-
managedApplicationThreadPool = true;
195-
this.applicationThreadPool = Executors.newCachedThreadPool();
196-
} else {
197-
this.applicationThreadPool = applicationThreadPool;
198-
}
193+
this.managedApplicationThreadPool = managedApplicationThreadPool;
194+
this.applicationThreadPool = applicationThreadPool;
199195
this.proxyServerSelector = proxyServerSelector;
200196
this.useRawUrl = useRawUrl;
201197
this.spdyEnabled = spdyEnabled;
@@ -635,6 +631,7 @@ public static class Builder {
635631
private boolean useRelativeURIsWithSSLProxies = Boolean.getBoolean(ASYNC_CLIENT + "useRelativeURIsWithSSLProxies");
636632
private ScheduledExecutorService reaper;
637633
private ExecutorService applicationThreadPool;
634+
private boolean managedApplicationThreadPool;
638635
private ProxyServerSelector proxyServerSelector = null;
639636
private SSLContext sslContext;
640637
private SSLEngineFactory sslEngineFactory;
@@ -1276,8 +1273,10 @@ public Thread newThread(Runnable r) {
12761273
}
12771274

12781275
if (applicationThreadPool == null) {
1276+
managedApplicationThreadPool = true;
1277+
int count = Runtime.getRuntime().availableProcessors();
12791278
applicationThreadPool =
1280-
Executors.newCachedThreadPool(new ThreadFactory() {
1279+
Executors.newFixedThreadPool(count, new ThreadFactory() {
12811280
final AtomicInteger counter = new AtomicInteger();
12821281
public Thread newThread(Runnable r) {
12831282
Thread t = new Thread(r,
@@ -1341,7 +1340,8 @@ public Thread newThread(Runnable r) {
13411340
spdyInitialWindowSize,
13421341
spdyMaxConcurrentStreams,
13431342
rfc6265CookieEncoding,
1344-
asyncConnectMode);
1343+
asyncConnectMode,
1344+
managedApplicationThreadPool);
13451345
}
13461346
}
13471347
}

0 commit comments

Comments
 (0)