@@ -54,6 +54,18 @@ public final class OkHttpClients {
54
54
*/
55
55
private static final ExecutorService executionExecutor = Tracers .wrap (new Dispatcher ().executorService ());
56
56
57
+ /** Shared dispatcher with static executor service. */
58
+ private static final Dispatcher dispatcher ;
59
+
60
+ static {
61
+ dispatcher = new Dispatcher (executionExecutor );
62
+ dispatcher .setMaxRequests (256 );
63
+ dispatcher .setMaxRequestsPerHost (256 );
64
+ }
65
+
66
+ /** Shared connection pool. */
67
+ private static final ConnectionPool connectionPool = new ConnectionPool (100 , 10 , TimeUnit .MINUTES );
68
+
57
69
/**
58
70
* The {@link ScheduledExecutorService} used for scheduling call retries. This thread pool is distinct from OkHttp's
59
71
* internal thread pool and from the thread pool used by {@link #executionExecutor}.
@@ -151,10 +163,9 @@ private static RemotingOkHttpClient createInternal(
151
163
client .connectionSpecs (createConnectionSpecs (config .enableGcmCipherSuites ()));
152
164
153
165
// increase default connection pool from 5 @ 5 minutes to 100 @ 10 minutes
154
- client .connectionPool (new ConnectionPool ( 100 , 10 , TimeUnit . MINUTES ) );
166
+ client .connectionPool (connectionPool );
155
167
156
- // dispatcher with static executor service
157
- client .dispatcher (createDispatcher ());
168
+ client .dispatcher (dispatcher );
158
169
159
170
return new RemotingOkHttpClient (
160
171
client .build (),
@@ -212,11 +223,4 @@ private static ImmutableList<ConnectionSpec> createConnectionSpecs(boolean enabl
212
223
ConnectionSpec .CLEARTEXT );
213
224
}
214
225
215
- private static Dispatcher createDispatcher () {
216
- Dispatcher dispatcher = new Dispatcher (executionExecutor );
217
- dispatcher .setMaxRequests (256 );
218
- dispatcher .setMaxRequestsPerHost (256 );
219
- return dispatcher ;
220
- }
221
-
222
226
}
0 commit comments