私はHttpClient 3..0.1をMultiThreadedHttpConnectionManager
使用しており、以下のコードを使用してページを取得し、そのページの最終的なリダイレクトされたURLも取得しています。
複数のスレッドがこのコードに並行してアクセスします。このコードをしばらく実行した後、継続的に取得し始めConnectionPoolTimeoutException
、それ以上ページが取得されません。
これは私が増やすべき値に関連していconnectionManagerParam
ますか、それともコードで何か間違ったことをしていますか?
GetMethod get = null;
try {
get = new GetMethod();
get.setURI(uri);
get.setFollowRedirects(false);
int status = httpClient.executeMethod(null, get, new HttpState());
String location = null;
int retry = 2;
if (get.getResponseHeader("location") != null) {
location = get.getResponseHeader("location").getValue();
}
while (retry > 0 && ((int) (status / 100) != 2) && ((int) (status / 100) == 3) && location.length() > 0) {
// To get the final redirected url.
uri = URLUtil.createAbsoluteURIWithFix(location, null);
get = new GetMethod();
get.setURI(uri);
get.setFollowRedirects(false);
status = httpClient.executeMethod(null, get, new HttpState());
if (get.getResponseHeader("location") != null) {
location = get.getResponseHeader("location").getValue();
}
retry--;
}
if (status == 200) {
uri = get.getURI();
String html = URLUtil.getResponseBodyAsString(get, charsets);
}
} catch (Exception e) {
} finally {
if (get != null) {
get.releaseConnection();
}
}
例外スタックトレース
org.apache.commons.httpclient.ConnectionPoolTimeoutException: Timeout waiting for connection
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.doGetConnection(MultiThreadedHttpConnectionManager.java:490)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.getConnectionWithTimeout(MultiThreadedHttpConnectionManager.java:394)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:152)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
メソッドを実行するたびに get.releaseConnection() を呼び出す必要がありますか? または現在のコーディングは問題ありませんか?