【发布时间】:2015-11-07 13:47:20
【问题描述】:
我在使用 Apache HTTPClient 的谷歌应用引擎上部署了一个应用。最近随着应用程序获得更多流量,我开始遇到超出套接字配额的异常。例外是
com.google.apphosting.api.ApiProxy$OverQuotaException: The API call remote_socket.SetSocketOptions() required more quota than is available.
我联系了 App Engine 团队,他们希望我检查我的应用是否泄漏了套接字。
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://www.spark.com");
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("param1", "val1"));
nvps.add(new BasicNameValuePair("param2", "val2"));
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
CloseableHttpResponse response = httpclient.execute(httpPost);
Document doc = null;
try {
HttpEntity entity = response.getEntity();
doc = Jsoup.parse(entity.getContent(), "UTF-8", "");
EntityUtils.consume(entity);
} finally {
response.close();
httpclient.close();
}
这就是我的 http 连接代码的样子。我做错了什么可能导致套接字泄漏吗?我可以做得更好吗?
【问题讨论】:
标签: java sockets google-app-engine http-post httpclient