@@ -157,7 +157,8 @@ private AsyncHttpClientConfig(int maxTotalConnections,
157
157
int spdyInitialWindowSize ,
158
158
int spdyMaxConcurrentStreams ,
159
159
boolean rfc6265CookieEncoding ,
160
- boolean asyncConnectMode ) {
160
+ boolean asyncConnectMode ,
161
+ boolean managedApplicationThreadPool ) {
161
162
162
163
this .maxTotalConnections = maxTotalConnections ;
163
164
this .maxConnectionPerHost = maxConnectionPerHost ;
@@ -189,13 +190,8 @@ private AsyncHttpClientConfig(int maxTotalConnections,
189
190
this .ioThreadMultiplier = ioThreadMultiplier ;
190
191
this .strict302Handling = strict302Handling ;
191
192
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 ;
199
195
this .proxyServerSelector = proxyServerSelector ;
200
196
this .useRawUrl = useRawUrl ;
201
197
this .spdyEnabled = spdyEnabled ;
@@ -635,6 +631,7 @@ public static class Builder {
635
631
private boolean useRelativeURIsWithSSLProxies = Boolean .getBoolean (ASYNC_CLIENT + "useRelativeURIsWithSSLProxies" );
636
632
private ScheduledExecutorService reaper ;
637
633
private ExecutorService applicationThreadPool ;
634
+ private boolean managedApplicationThreadPool ;
638
635
private ProxyServerSelector proxyServerSelector = null ;
639
636
private SSLContext sslContext ;
640
637
private SSLEngineFactory sslEngineFactory ;
@@ -1276,8 +1273,10 @@ public Thread newThread(Runnable r) {
1276
1273
}
1277
1274
1278
1275
if (applicationThreadPool == null ) {
1276
+ managedApplicationThreadPool = true ;
1277
+ int count = Runtime .getRuntime ().availableProcessors ();
1279
1278
applicationThreadPool =
1280
- Executors .newCachedThreadPool ( new ThreadFactory () {
1279
+ Executors .newFixedThreadPool ( count , new ThreadFactory () {
1281
1280
final AtomicInteger counter = new AtomicInteger ();
1282
1281
public Thread newThread (Runnable r ) {
1283
1282
Thread t = new Thread (r ,
@@ -1341,7 +1340,8 @@ public Thread newThread(Runnable r) {
1341
1340
spdyInitialWindowSize ,
1342
1341
spdyMaxConcurrentStreams ,
1343
1342
rfc6265CookieEncoding ,
1344
- asyncConnectMode );
1343
+ asyncConnectMode ,
1344
+ managedApplicationThreadPool );
1345
1345
}
1346
1346
}
1347
1347
}
0 commit comments