ConnectionPoolTimeoutException:等待池中的连接超时 [英] ConnectionPoolTimeoutException: timeout waiting for connection from pool

查看:263
本文介绍了ConnectionPoolTimeoutException:等待池中的连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,该应用程序一直为json数据调用api,很快我就看到了超时等待池中的连接"异常,我在Google上四处搜寻,发现这是由未消耗内容引起的连接泄漏,因此我更新了使用jsondata后关闭inputstream的代码,但仍然出现那些连接超时异常,这是我的代码:

I have app that keep calling an api for json data, and pretty quickly i saw this 'Timeout waiting for connection from pool' exception, I googled around and found that's a connection leak caused by content not consumed, so i updated the code to close the inputstream after consume the jsondata, but still got those connection timeout exception, here is my code:

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();
   }
}

这里的包装逻辑有点复杂,但是最终我认为通过关闭输入流应该起作用,有什么想法吗?谢谢!

the wrapping logic here is kind of complicated, but eventually i think by closing the inputstream should work, any thoughts? Thanks!

推荐答案

   try {
     response = request.execute();
     if (response.isSuccessStatusCode()) {
       return response.getContent();
     }
   } catch (Exception e) {
     throw new Exception();
   }finally{
      //TODO release conn or abort
   }

这篇关于ConnectionPoolTimeoutException:等待池中的连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆