0
我有应用程序,不断调用一个API的JSON数据,并很快我看到这个'超时等待连接池'异常,我GOOGLE了周围,发现这是一个连接泄漏引起的内容不会被消耗,所以我更新的代码消耗jsondata后关闭InputStream,但还是得到了那些连接超时异常,这里是我的代码:ConnectionPoolTimeoutException:超时等待连接池
InputStream is = ApiUtil.getAsStream(Api.get(bookUrl).param("limit","500").param("bookId", bid).enable(Options.LongRunning), 3);
List<JsonBook> books = mapper.readValue(is, BOOK_TYPE);
is.close()
Api:
private JsonHttpClient client;
public APIForGet get(String endpoint) {
return new APIForGet(this.client, endpoint);
}
ApiUtil:
public static InputStream getAsStream(APIForGet get, Iterable<Long>retries) {
return get.asStream();
}
APIForGet:
private JsonHttpClient client;
public InputStream asStream() {
return this.client.getAsStream(this.hostname, this.port, this.endpoint, params, optionsArray());
}
JsonHttpClientImpl:
public InputStream getAsStream(Optional<String> host, Optional<Integer> port,String path, Multimap<String, String> param, Options ... options) {
HttpResponse reponse;
try {
response = request.execute();
if (response.isSuccessStatusCode()) {
return response.getContent();
}
} catch (Exception e) {
throw new Exception();
}
}
这里的包装逻辑是一种复杂的,但最终我想通过关闭输入流应该工作,任何想法?谢谢!
你有任何这等领先? – asgs