hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Becke <be...@u.washington.edu>
Subject Re: Moving from HttpMultiClient to HttpClient
Date Wed, 18 Dec 2002 00:05:41 GMT
Please do.

Mike

On Tuesday, December 17, 2002, at 02:54 AM, Ortwin Glück 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  
>> from multiple threads.  Hope this helps.
>> Mike
>> ---------------------------------------------------------------------- 
>> --
>> import org.apache.commons.httpclient.HttpClient;
>> import  
>> 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 = new HttpClient(              
>> new MultiThreadedHttpConnectionManager()         );
>>                 // set the default host to google news
>>         httpClient.getHostConfiguration().setHost( "news.google.com",  
>> -1, "http" );
>>                 // create 4 reading threads
>>         ReadSomeGoogle[] threads = new ReadSomeGoogle[4];
>>         for (int i = 0; i < threads.length; i++) {
>>             threads[i] = new ReadSomeGoogle( httpClient, i + 1 );
>>         }
>>                 // start the threads
>>         for (int j = 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  
>> ) {
>>             this.httpClient = httpClient;
>>             this.id = id;
>>         }
>>                 public void run() {
>>                         GetMethod get = new GetMethod("/");
>>             get.setFollowRedirects(true);                             
>> try {
>>                                 System.out.println( id + " - about to  
>> get something" );
>>                 httpClient.executeMethod( get );
>>                 System.out.println( id + " - get executed" );
>>                 byte[] bytes = get.getResponseBody();
>>                 System.out.println( id + " - " + bytes.length + "  
>> bytes read" );
>>                             } catch ( Exception e ) {                  
>>                System.out.println( id + " - error: " + e );            
>>   } finally {
>>                 get.releaseConnection();
>>                 System.out.println( id + " - connection released" );
>>             }
>>                     }
>>            }
>>     }
>> ---------------------------------------------------------------------- 
>> --
>> On Monday, December 16, 2002, at 08:24 PM, dion@multitask.com.au  
>> 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....
>>> -- 
>>> dIon Gillard, Multitask Consulting
>>> Blog:      http://www.freeroller.net/page/dion/Weblog
>>> Work:      http://www.multitask.com.au
>>>
>>>
>>> -- 
>>> To unsubscribe, e-mail:    
>>> <mailto:commons-httpclient-dev-unsubscribe@jakarta.apache.org>
>>> For additional commands, e-mail:  
>>> <mailto:commons-httpclient-dev-help@jakarta.apache.org>
>>>
>> ---------------------------------------------------------------------- 
>> --
>> --
>> To unsubscribe, e-mail:    
>> <mailto:commons-httpclient-dev-unsubscribe@jakarta.apache.org>
>> For additional commands, e-mail:  
>> <mailto:commons-httpclient-dev-help@jakarta.apache.org>
>
> -- 
> _________________________________________________________________
>  NOSE applied intelligence ag
>                                    [www]      http://www.nose.ch
>  ortwin glück                      [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:    
> <mailto:commons-httpclient-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:  
> <mailto:commons-httpclient-dev-help@jakarta.apache.org>
>


Mime
View raw message