Return-Path: Delivered-To: apmail-jakarta-httpclient-user-archive@www.apache.org Received: (qmail 619 invoked from network); 25 Oct 2005 22:42:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 25 Oct 2005 22:42:24 -0000 Received: (qmail 2268 invoked by uid 500); 25 Oct 2005 22:42:23 -0000 Delivered-To: apmail-jakarta-httpclient-user-archive@jakarta.apache.org Received: (qmail 2247 invoked by uid 500); 25 Oct 2005 22:42:22 -0000 Mailing-List: contact httpclient-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: "HttpClient User Discussion" Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-user@jakarta.apache.org Received: (qmail 2236 invoked by uid 99); 25 Oct 2005 22:42:22 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Oct 2005 15:42:22 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=HTML_MESSAGE X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [69.20.119.35] (HELO mail.arizonabay.com) (69.20.119.35) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Oct 2005 15:42:20 -0700 Received: from DEREKMOBILE (S0106001217da6d69.cg.shawcable.net [68.144.67.129]) (authenticated bits=0) by mail.arizonabay.com (8.12.11/8.12.11) with ESMTP id j9PMg0pJ014502 for ; Tue, 25 Oct 2005 18:42:00 -0400 Message-Id: <200510252242.j9PMg0pJ014502@mail.arizonabay.com> From: "Derek Sweet" To: Subject: Is it possible to interupt and executeMethod() call? Date: Tue, 25 Oct 2005 16:42:20 -0600 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_007A_01C5D983.11C58E30" X-Mailer: Microsoft Office Outlook, Build 11.0.5510 Thread-Index: AcXZtVv5Qhv4KvobR8Wkxkkir6qAuw== X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_NextPart_000_007A_01C5D983.11C58E30 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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(); } } } } ------=_NextPart_000_007A_01C5D983.11C58E30--