Im doing something similar except Im using the MultiThreadedHttpConnectionManager.
http://hc.apache.org/httpclient-3.x/threading.html Doing that you should be safe. Just remember to set the options described in the above link. Andy > Date: Thu, 16 Dec 2010 14:42:36 +0000 > Subject: Using an instance of HttpGet/HttpPost across multiple threads > From: [email protected] > To: [email protected] > > 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: [email protected] > For additional commands, e-mail: [email protected] >
