0
我有一個應用程序部署在使用Apache HTTPClient的谷歌應用程序引擎上。最近,隨着應用獲得更多流量,我已經開始遇到超出套接字配額的例外情況。唯一的例外是我的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連接代碼的樣子。我是否做了可能導致套接字泄漏的錯誤?我可以做更好的事嗎?