OkHttpClient
是否可以限制活动连接数?如果达到了限制,就不会选择和建立新的连接吗?
我的应用程序同时启动了很多连接。
Dispatcher dispatcher = new Dispatcher();
dispatcher.setMaxRequests(100);
dispatcher.setMaxRequestsPerHost(10);
OkHttpClient client = new OkHttpClient.Builder()
.dispatcher(dispatcher)
.build();
OkHttpClient.Builder
上设置ConnectionPool来尝试配置最大空闲网络连接数。int maxConnections = 5;
int keepAliveDuration = 15000;
ConnectionPool cp = new ConnectionPool(maxConnections, keepAliveDuration, TimeUnit.MILLISECONDS);
new OkHttpClient.Builder()
.connectionPool(cp)
.build();