hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Derek Sweet" <de...@arizonabay.com>
Subject Is it possible to interupt and executeMethod() call?
Date Tue, 25 Oct 2005 22:42:20 GMT
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
 public AsyncHTTPSingleton(){
 public void CreateAsyncHTTP(String url, String parms, String method, int
UUID, int PPID, String returnAddress){
  HttpClient tempHttpClient = new HttpClient(new
  GetMethod tempMethod = new GetMethod(url);
  asyncStruct[UUID][PPID] = new AsyncHTTP(UUID, PPID, returnAddress,
tempHttpClient, tempMethod);
 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("");
      StrResponse = myMethod.getResponseBodyAsString();
   } catch (HttpException he) {
   } catch (IOException ioe){
   } finally {
   GetMethod tempReturnMethod = new GetMethod(returnAddress + "?PPID=" +
      StrResponse = tempReturnMethod.getResponseBodyAsString();
   } catch (HttpException he) {
   } catch (IOException ioe){
   } finally {

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message