Return-Path: Mailing-List: contact commons-httpclient-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-httpclient-dev@jakarta.apache.org Received: (qmail 21256 invoked by uid 98); 18 Dec 2002 00:06:59 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Received: (qmail 21236 invoked from network); 18 Dec 2002 00:06:57 -0000 Received: from daedalus.apache.org (HELO apache.org) (63.251.56.142) by nagoya.betaversion.org with SMTP; 18 Dec 2002 00:06:57 -0000 Received: (qmail 1312 invoked by uid 500); 18 Dec 2002 00:05:41 -0000 Received: (qmail 1305 invoked from network); 18 Dec 2002 00:05:41 -0000 Received: from mxout4.cac.washington.edu (140.142.33.19) by daedalus.apache.org with SMTP; 18 Dec 2002 00:05:41 -0000 Received: from mailscan-out3.cac.washington.edu (mailscan-out3.cac.washington.edu [140.142.32.170]) by mxout4.cac.washington.edu (8.12.1+UW01.12/8.12.1+UW02.11) with SMTP id gBI05l5C023246 for ; Tue, 17 Dec 2002 16:05:48 -0800 Received: FROM smtp.washington.edu BY mailscan-out3.cac.washington.edu ; Tue Dec 17 16:05:47 2002 -0800 Received: from u.washington.edu (pool-129-44-172-239.bos.east.verizon.net [129.44.172.239]) (authenticated bits=0) by smtp.washington.edu (8.12.1+UW01.12/8.12.1+UW02.11) with ESMTP id gBI05jmY031902 (version=TLSv1/SSLv3 cipher=DES-CBC3-SHA bits=168 verify=NOT) for ; Tue, 17 Dec 2002 16:05:46 -0800 Date: Tue, 17 Dec 2002 19:05:41 -0500 Subject: Re: Moving from HttpMultiClient to HttpClient Content-Type: text/plain; delsp=yes; charset=ISO-8859-1; format=flowed Mime-Version: 1.0 (Apple Message framework v548) From: Michael Becke To: "Commons HttpClient Project" Content-Transfer-Encoding: quoted-printable In-Reply-To: <3DFED84D.3080200@nose.ch> Message-Id: <7246EB02-121C-11D7-927F-00306557E112@u.washington.edu> X-Mailer: Apple Mail (2.548) X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Please do. Mike On Tuesday, December 17, 2002, at 02:54 AM, Ortwin Gl=FCck wrote: > Mike, can we include this in our Samples? > > Odi > > Michael Becke wrote: >> Here's a simple example of how to get started with the HttpClient =20 >> from multiple threads. Hope this helps. >> Mike >> = ----------------------------------------------------------------------=20= >> -- >> import org.apache.commons.httpclient.HttpClient; >> import =20 >> org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; >> import org.apache.commons.httpclient.methods.GetMethod; >> /** >> * An example that reads news.google.com from multiple threads. >> */ >> public class MultiThreadedExample { >> /** >> * Constructor for MultiThreadedExample. >> */ >> public MultiThreadedExample() { >> super(); >> } >> public static void main(String[] args) { >> HttpClient httpClient =3D new HttpClient( = =20 >> new MultiThreadedHttpConnectionManager() ); >> // set the default host to google news >> httpClient.getHostConfiguration().setHost( "news.google.com", = =20 >> -1, "http" ); >> // create 4 reading threads >> ReadSomeGoogle[] threads =3D new ReadSomeGoogle[4]; >> for (int i =3D 0; i < threads.length; i++) { >> threads[i] =3D new ReadSomeGoogle( httpClient, i + 1 ); >> } >> // start the threads >> for (int j =3D 0; j < threads.length; j++) { >> threads[j].start(); >> } >> } >> /** >> * A thread that performs a GET from an HttpClient. >> */ >> static class ReadSomeGoogle extends Thread { >> private HttpClient httpClient; >> private int id; >> public ReadSomeGoogle( HttpClient httpClient, int id =20= >> ) { >> this.httpClient =3D httpClient; >> this.id =3D id; >> } >> public void run() { >> GetMethod get =3D new GetMethod("/"); >> get.setFollowRedirects(true); =20= >> try { >> System.out.println( id + " - about to = =20 >> get something" ); >> httpClient.executeMethod( get ); >> System.out.println( id + " - get executed" ); >> byte[] bytes =3D get.getResponseBody(); >> System.out.println( id + " - " + bytes.length + " =20 >> bytes read" ); >> } catch ( Exception e ) { = =20 >> System.out.println( id + " - error: " + e ); = =20 >> } finally { >> get.releaseConnection(); >> System.out.println( id + " - connection released" ); >> } >> } >> } >> } >> = ----------------------------------------------------------------------=20= >> -- >> On Monday, December 16, 2002, at 08:24 PM, dion@multitask.com.au =20 >> wrote: >>> Is there a good summary somewhere of the changes made so that the = new >>> HttpClient can be used in place of the old MultiClient? >>> >>> I was hoping for something other than a diff/visual scan.... >>> --=20 >>> dIon Gillard, Multitask Consulting >>> Blog: http://www.freeroller.net/page/dion/Weblog >>> Work: http://www.multitask.com.au >>> >>> >>> --=20 >>> To unsubscribe, e-mail: =20 >>> >>> For additional commands, e-mail: =20 >>> >>> >> = ----------------------------------------------------------------------=20= >> -- >> -- >> To unsubscribe, e-mail: =20 >> >> For additional commands, e-mail: =20 >> > > --=20 > _________________________________________________________________ > NOSE applied intelligence ag > [www] http://www.nose.ch > ortwin gl=FCck [email] ortwin.glueck@nose.ch > hardturmstrasse 171 [pgp key] 0x81CF3416 > 8005 zurich [office] +41-1-277 57 35 > switzerland [fax] +41-1-277 57 12 > > > -- > To unsubscribe, e-mail: =20 > > For additional commands, e-mail: =20 > >