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:[EMAIL PROTECTED] 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" <[EMAIL PROTECTED]> 26.10.2005 00:42 Please respond to "HttpClient User Discussion" To <[email protected]> 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
