HttpClient 3..0.1을 MultiThreadedHttpConnectionManager
과 함께 사용하고 있으며 아래 코드를 사용하여 페이지를 가져오고 해당 페이지의 최종 리디렉션 된 URL을 가져옵니다.HttpMethod.releaseConnection() usage
여러 스레드가이 코드를 병렬로 액세스합니다. 이 코드를 얼마 동안 실행 한 후에는 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()를 호출해야합니까 예외 스택 트레이스는 방법을 실행? 또는 현재 코딩 괜찮습니까?
get.releaseConnection(); - 첫 번째 거래를 마감하지 않습니까? – razor
get의 인스턴스가 루프 –
아아 내의 영향에 의해 덮어 쓰여졌습니다 ... 루프 내에서 새로운 'GetMethod()'가 보이지 않았습니다. – razor