You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Derek Sweet <de...@arizonabay.com> on 2005/10/26 00:42:20 UTC
Is it possible to interupt and executeMethod() call?
I am doing some asynchronous creation and calling of the HttpClient object.
Imagine 10 threads being started, each with their own HttpClient object
using the MultiThreadedManager technique outlined in the
MultiThreadedExample.java. I want to be able to kill any remaining processes
that are still waiting for a response once any of the 10 instances have
returned. I want to do this so I can keep the memory management on my server
optimal. I have tried making a call to releaseConnection() on the GetMethod,
and have also tried changing the timeout to 10 milliseconds and neither of
these options seem to be interupting the executeMethod() call. It still
seems to be waiting for the execution to finish. I know this because I have
written my own page on another server that takes 10 seconds to respond and
it always takes the full 10 seconds before the process moves on, even if I
try to interupt. Thank you for any help anyone can offer. Here is my code,
if it helps:
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.GetMethod;
import java.net.*;
import java.io.*;
public class AsyncHTTPSingleton{
private volatile AsyncHTTP[][] asyncStruct = new AsyncHTTP[999][999];
private static HttpClient globalHttpClient = new HttpClient(new
MultiThreadedHttpConnectionManager());
public AsyncHTTPSingleton(){
}
public void CreateAsyncHTTP(String url, String parms, String method, int
UUID, int PPID, String returnAddress){
HttpClient tempHttpClient = new HttpClient(new
MultiThreadedHttpConnectionManager());
GetMethod tempMethod = new GetMethod(url);
tempMethod.setFollowRedirects(true);
asyncStruct[UUID][PPID] = new AsyncHTTP(UUID, PPID, returnAddress,
tempHttpClient, tempMethod);
asyncStruct[UUID][PPID].start();
asyncStruct[UUID][PPID].myHttpClient.interrupt();
asyncStruct[UUID][PPID].myHttpClient.setConnectionTimeout(10);
}
static class AsyncHTTP extends Thread{
public HttpClient myHttpClient;
private HttpMethod myMethod;
private int UUID;
private int PPID;
private String returnAddress;
public AsyncHTTP(int UUIDToUse, int PPIDToUse, String returnAddressToUse,
HttpClient httpClientToUse, GetMethod methodToUse){
this.UUID = UUIDToUse;
this.PPID = PPIDToUse;
this.returnAddress = returnAddressToUse;
this.myHttpClient = httpClientToUse;
this.myMethod = methodToUse;
}
public void run(){
String StrResponse = new String("");
try{
myHttpClient.executeMethod(myMethod);
StrResponse = myMethod.getResponseBodyAsString();
} catch (HttpException he) {
} catch (IOException ioe){
} finally {
myMethod.releaseConnection();
}
globalHttpClient.setConnectionTimeout(10000);
GetMethod tempReturnMethod = new GetMethod(returnAddress + "?PPID=" +
PPID);
try{
globalHttpClient.executeMethod(tempReturnMethod);
StrResponse = tempReturnMethod.getResponseBodyAsString();
} catch (HttpException he) {
} catch (IOException ioe){
} finally {
tempReturnMethod.releaseConnection();
}
}
}
}
RE: Is it possible to interupt and executeMethod() call?
Posted by Derek Sweet <de...@arizonabay.com>.
Sorry for all the emails everyone, and thank you Roland. I am now using
version 3.0 and the abort command works perfectly! I will stay on the list
for a while still and hopefully be able to help someone else. Thank you!
Derek
-----Original Message-----
From: Roland Weber [mailto:ROLWEBER@de.ibm.com]
Sent: Wednesday, October 26, 2005 12:06 AM
To: HttpClient User Discussion
Subject: Re: Is it possible to interupt and executeMethod() call?
Hello Derek,
use HttpMethod.abort() instead of releaseConnection().
hope that helps,
Roland
"Derek Sweet" <de...@arizonabay.com>
26.10.2005 00:42
Please respond to
"HttpClient User Discussion"
To
<ht...@jakarta.apache.org>
cc
Subject
Is it possible to interupt and executeMethod() call?
I am doing some asynchronous creation and calling of the HttpClient
object.
Imagine 10 threads being started, each with their own HttpClient object
using the MultiThreadedManager technique outlined in the
MultiThreadedExample.java. I want to be able to kill any remaining
processes
that are still waiting for a response once any of the 10 instances have
returned. I want to do this so I can keep the memory management on my
server
optimal. I have tried making a call to releaseConnection() on the
GetMethod,
and have also tried changing the timeout to 10 milliseconds and neither of
these options seem to be interupting the executeMethod() call. It still
seems to be waiting for the execution to finish. I know this because I
have
written my own page on another server that takes 10 seconds to respond and
it always takes the full 10 seconds before the process moves on, even if I
try to interupt. Thank you for any help anyone can offer. Here is my code,
if it helps:
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.GetMethod;
import java.net.*;
import java.io.*;
public class AsyncHTTPSingleton{
private volatile AsyncHTTP[][] asyncStruct = new AsyncHTTP[999][999];
private static HttpClient globalHttpClient = new HttpClient(new
MultiThreadedHttpConnectionManager());
public AsyncHTTPSingleton(){
}
public void CreateAsyncHTTP(String url, String parms, String method, int
UUID, int PPID, String returnAddress){
HttpClient tempHttpClient = new HttpClient(new
MultiThreadedHttpConnectionManager());
GetMethod tempMethod = new GetMethod(url);
tempMethod.setFollowRedirects(true);
asyncStruct[UUID][PPID] = new AsyncHTTP(UUID, PPID, returnAddress,
tempHttpClient, tempMethod);
asyncStruct[UUID][PPID].start();
asyncStruct[UUID][PPID].myHttpClient.interrupt();
asyncStruct[UUID][PPID].myHttpClient.setConnectionTimeout(10);
}
static class AsyncHTTP extends Thread{
public HttpClient myHttpClient;
private HttpMethod myMethod;
private int UUID;
private int PPID;
private String returnAddress;
public AsyncHTTP(int UUIDToUse, int PPIDToUse, String
returnAddressToUse,
HttpClient httpClientToUse, GetMethod methodToUse){
this.UUID = UUIDToUse;
this.PPID = PPIDToUse;
this.returnAddress = returnAddressToUse;
this.myHttpClient = httpClientToUse;
this.myMethod = methodToUse;
}
public void run(){
String StrResponse = new String("");
try{
myHttpClient.executeMethod(myMethod);
StrResponse = myMethod.getResponseBodyAsString();
} catch (HttpException he) {
} catch (IOException ioe){
} finally {
myMethod.releaseConnection();
}
globalHttpClient.setConnectionTimeout(10000);
GetMethod tempReturnMethod = new GetMethod(returnAddress + "?PPID=" +
PPID);
try{
globalHttpClient.executeMethod(tempReturnMethod);
StrResponse = tempReturnMethod.getResponseBodyAsString();
} catch (HttpException he) {
} catch (IOException ioe){
} finally {
tempReturnMethod.releaseConnection();
}
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
RE: Is it possible to interupt and executeMethod() call?
Posted by Derek Sweet <de...@arizonabay.com>.
Is the reason I am having problems with the abort() method because I'm still
using version 2.0 of HttpClient?
Derek
-----Original Message-----
From: Roland Weber [mailto:ROLWEBER@de.ibm.com]
Sent: Wednesday, October 26, 2005 12:06 AM
To: HttpClient User Discussion
Subject: Re: Is it possible to interupt and executeMethod() call?
Hello Derek,
use HttpMethod.abort() instead of releaseConnection().
hope that helps,
Roland
"Derek Sweet" <de...@arizonabay.com>
26.10.2005 00:42
Please respond to
"HttpClient User Discussion"
To
<ht...@jakarta.apache.org>
cc
Subject
Is it possible to interupt and executeMethod() call?
I am doing some asynchronous creation and calling of the HttpClient
object.
Imagine 10 threads being started, each with their own HttpClient object
using the MultiThreadedManager technique outlined in the
MultiThreadedExample.java. I want to be able to kill any remaining
processes
that are still waiting for a response once any of the 10 instances have
returned. I want to do this so I can keep the memory management on my
server
optimal. I have tried making a call to releaseConnection() on the
GetMethod,
and have also tried changing the timeout to 10 milliseconds and neither of
these options seem to be interupting the executeMethod() call. It still
seems to be waiting for the execution to finish. I know this because I
have
written my own page on another server that takes 10 seconds to respond and
it always takes the full 10 seconds before the process moves on, even if I
try to interupt. Thank you for any help anyone can offer. Here is my code,
if it helps:
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.GetMethod;
import java.net.*;
import java.io.*;
public class AsyncHTTPSingleton{
private volatile AsyncHTTP[][] asyncStruct = new AsyncHTTP[999][999];
private static HttpClient globalHttpClient = new HttpClient(new
MultiThreadedHttpConnectionManager());
public AsyncHTTPSingleton(){
}
public void CreateAsyncHTTP(String url, String parms, String method, int
UUID, int PPID, String returnAddress){
HttpClient tempHttpClient = new HttpClient(new
MultiThreadedHttpConnectionManager());
GetMethod tempMethod = new GetMethod(url);
tempMethod.setFollowRedirects(true);
asyncStruct[UUID][PPID] = new AsyncHTTP(UUID, PPID, returnAddress,
tempHttpClient, tempMethod);
asyncStruct[UUID][PPID].start();
asyncStruct[UUID][PPID].myHttpClient.interrupt();
asyncStruct[UUID][PPID].myHttpClient.setConnectionTimeout(10);
}
static class AsyncHTTP extends Thread{
public HttpClient myHttpClient;
private HttpMethod myMethod;
private int UUID;
private int PPID;
private String returnAddress;
public AsyncHTTP(int UUIDToUse, int PPIDToUse, String
returnAddressToUse,
HttpClient httpClientToUse, GetMethod methodToUse){
this.UUID = UUIDToUse;
this.PPID = PPIDToUse;
this.returnAddress = returnAddressToUse;
this.myHttpClient = httpClientToUse;
this.myMethod = methodToUse;
}
public void run(){
String StrResponse = new String("");
try{
myHttpClient.executeMethod(myMethod);
StrResponse = myMethod.getResponseBodyAsString();
} catch (HttpException he) {
} catch (IOException ioe){
} finally {
myMethod.releaseConnection();
}
globalHttpClient.setConnectionTimeout(10000);
GetMethod tempReturnMethod = new GetMethod(returnAddress + "?PPID=" +
PPID);
try{
globalHttpClient.executeMethod(tempReturnMethod);
StrResponse = tempReturnMethod.getResponseBodyAsString();
} catch (HttpException he) {
} catch (IOException ioe){
} finally {
tempReturnMethod.releaseConnection();
}
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
RE: Is it possible to interupt and executeMethod() call?
Posted by Derek Sweet <de...@arizonabay.com>.
Hey Roland. Thanx for the help. When I try and compile my .java file with
the abort command I am getting a 'symbol not found' error. Is there
something I need to import to get that function?
Derek
-----Original Message-----
From: Roland Weber [mailto:ROLWEBER@de.ibm.com]
Sent: Wednesday, October 26, 2005 12:06 AM
To: HttpClient User Discussion
Subject: Re: Is it possible to interupt and executeMethod() call?
Hello Derek,
use HttpMethod.abort() instead of releaseConnection().
hope that helps,
Roland
"Derek Sweet" <de...@arizonabay.com>
26.10.2005 00:42
Please respond to
"HttpClient User Discussion"
To
<ht...@jakarta.apache.org>
cc
Subject
Is it possible to interupt and executeMethod() call?
I am doing some asynchronous creation and calling of the HttpClient
object.
Imagine 10 threads being started, each with their own HttpClient object
using the MultiThreadedManager technique outlined in the
MultiThreadedExample.java. I want to be able to kill any remaining
processes
that are still waiting for a response once any of the 10 instances have
returned. I want to do this so I can keep the memory management on my
server
optimal. I have tried making a call to releaseConnection() on the
GetMethod,
and have also tried changing the timeout to 10 milliseconds and neither of
these options seem to be interupting the executeMethod() call. It still
seems to be waiting for the execution to finish. I know this because I
have
written my own page on another server that takes 10 seconds to respond and
it always takes the full 10 seconds before the process moves on, even if I
try to interupt. Thank you for any help anyone can offer. Here is my code,
if it helps:
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.GetMethod;
import java.net.*;
import java.io.*;
public class AsyncHTTPSingleton{
private volatile AsyncHTTP[][] asyncStruct = new AsyncHTTP[999][999];
private static HttpClient globalHttpClient = new HttpClient(new
MultiThreadedHttpConnectionManager());
public AsyncHTTPSingleton(){
}
public void CreateAsyncHTTP(String url, String parms, String method, int
UUID, int PPID, String returnAddress){
HttpClient tempHttpClient = new HttpClient(new
MultiThreadedHttpConnectionManager());
GetMethod tempMethod = new GetMethod(url);
tempMethod.setFollowRedirects(true);
asyncStruct[UUID][PPID] = new AsyncHTTP(UUID, PPID, returnAddress,
tempHttpClient, tempMethod);
asyncStruct[UUID][PPID].start();
asyncStruct[UUID][PPID].myHttpClient.interrupt();
asyncStruct[UUID][PPID].myHttpClient.setConnectionTimeout(10);
}
static class AsyncHTTP extends Thread{
public HttpClient myHttpClient;
private HttpMethod myMethod;
private int UUID;
private int PPID;
private String returnAddress;
public AsyncHTTP(int UUIDToUse, int PPIDToUse, String
returnAddressToUse,
HttpClient httpClientToUse, GetMethod methodToUse){
this.UUID = UUIDToUse;
this.PPID = PPIDToUse;
this.returnAddress = returnAddressToUse;
this.myHttpClient = httpClientToUse;
this.myMethod = methodToUse;
}
public void run(){
String StrResponse = new String("");
try{
myHttpClient.executeMethod(myMethod);
StrResponse = myMethod.getResponseBodyAsString();
} catch (HttpException he) {
} catch (IOException ioe){
} finally {
myMethod.releaseConnection();
}
globalHttpClient.setConnectionTimeout(10000);
GetMethod tempReturnMethod = new GetMethod(returnAddress + "?PPID=" +
PPID);
try{
globalHttpClient.executeMethod(tempReturnMethod);
StrResponse = tempReturnMethod.getResponseBodyAsString();
} catch (HttpException he) {
} catch (IOException ioe){
} finally {
tempReturnMethod.releaseConnection();
}
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: Is it possible to interupt and executeMethod() call?
Posted by Roland Weber <RO...@de.ibm.com>.
Hello Derek,
use HttpMethod.abort() instead of releaseConnection().
hope that helps,
Roland
"Derek Sweet" <de...@arizonabay.com>
26.10.2005 00:42
Please respond to
"HttpClient User Discussion"
To
<ht...@jakarta.apache.org>
cc
Subject
Is it possible to interupt and executeMethod() call?
I am doing some asynchronous creation and calling of the HttpClient
object.
Imagine 10 threads being started, each with their own HttpClient object
using the MultiThreadedManager technique outlined in the
MultiThreadedExample.java. I want to be able to kill any remaining
processes
that are still waiting for a response once any of the 10 instances have
returned. I want to do this so I can keep the memory management on my
server
optimal. I have tried making a call to releaseConnection() on the
GetMethod,
and have also tried changing the timeout to 10 milliseconds and neither of
these options seem to be interupting the executeMethod() call. It still
seems to be waiting for the execution to finish. I know this because I
have
written my own page on another server that takes 10 seconds to respond and
it always takes the full 10 seconds before the process moves on, even if I
try to interupt. Thank you for any help anyone can offer. Here is my code,
if it helps:
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.GetMethod;
import java.net.*;
import java.io.*;
public class AsyncHTTPSingleton{
private volatile AsyncHTTP[][] asyncStruct = new AsyncHTTP[999][999];
private static HttpClient globalHttpClient = new HttpClient(new
MultiThreadedHttpConnectionManager());
public AsyncHTTPSingleton(){
}
public void CreateAsyncHTTP(String url, String parms, String method, int
UUID, int PPID, String returnAddress){
HttpClient tempHttpClient = new HttpClient(new
MultiThreadedHttpConnectionManager());
GetMethod tempMethod = new GetMethod(url);
tempMethod.setFollowRedirects(true);
asyncStruct[UUID][PPID] = new AsyncHTTP(UUID, PPID, returnAddress,
tempHttpClient, tempMethod);
asyncStruct[UUID][PPID].start();
asyncStruct[UUID][PPID].myHttpClient.interrupt();
asyncStruct[UUID][PPID].myHttpClient.setConnectionTimeout(10);
}
static class AsyncHTTP extends Thread{
public HttpClient myHttpClient;
private HttpMethod myMethod;
private int UUID;
private int PPID;
private String returnAddress;
public AsyncHTTP(int UUIDToUse, int PPIDToUse, String
returnAddressToUse,
HttpClient httpClientToUse, GetMethod methodToUse){
this.UUID = UUIDToUse;
this.PPID = PPIDToUse;
this.returnAddress = returnAddressToUse;
this.myHttpClient = httpClientToUse;
this.myMethod = methodToUse;
}
public void run(){
String StrResponse = new String("");
try{
myHttpClient.executeMethod(myMethod);
StrResponse = myMethod.getResponseBodyAsString();
} catch (HttpException he) {
} catch (IOException ioe){
} finally {
myMethod.releaseConnection();
}
globalHttpClient.setConnectionTimeout(10000);
GetMethod tempReturnMethod = new GetMethod(returnAddress + "?PPID=" +
PPID);
try{
globalHttpClient.executeMethod(tempReturnMethod);
StrResponse = tempReturnMethod.getResponseBodyAsString();
} catch (HttpException he) {
} catch (IOException ioe){
} finally {
tempReturnMethod.releaseConnection();
}
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org