hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Short <...@benshort.co.uk>
Subject Using an instance of HttpGet/HttpPost across multiple threads
Date Thu, 16 Dec 2010 14:42:36 GMT
Hi,

Will I run into any problems with the following code? Specifically
using the httpGet in more than one thread?


// might pass in a ThreadSafeClientConnManager here
        final DefaultHttpClient httpclient = new DefaultHttpClient();

        List<HttpHost> hosts = new ArrayList<HttpHost>();
        hosts.add(new HttpHost("www.host1.com"));
        hosts.add(new HttpHost("www.host2.com"));
        hosts.add(new HttpHost("www.host3.com"));

        String request = "/path/to/something?name=value&name1=value1";

        final HttpGet httpGet = new HttpGet(request);
        // set some headers here.

        for ( final HttpHost host : hosts ) {
            taskExecutor.execute(new Runnable() {
                public void run() {

                    try {
                        HttpResponse response =
httpclient.execute(host, httpGet);
                        // do what every with the response

                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }
            });
        }

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message