hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roland Weber <ROLWE...@de.ibm.com>
Subject Re: Is it possible to interupt and executeMethod() call?
Date Wed, 26 Oct 2005 06:05:55 GMT
Hello Derek,

use HttpMethod.abort() instead of releaseConnection().

hope that helps,
  Roland




"Derek Sweet" <derek@arizonabay.com> 
26.10.2005 00:42
Please respond to
"HttpClient User Discussion"


To
<httpclient-user@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


Mime
View raw message