Ashwin Surana
Ashwin Surana

Reputation: 876

Why should there be only one instance of HTTPClient?

Read tutorials on using httpClient(HttpClient API by Apache), it said that we should have only one instance of HttpClient. So Below are my doubts..

  1. Why is it so?
  2. Can I have two HttpClient on different threads.?

Upvotes: 2

Views: 2084

Answers (1)

isnot2bad
isnot2bad

Reputation: 24454

Because your HttpClient instance holds session data like cookies, credentials and so on. Even if you only use one single HttpClient instance, you're able to use multiple connections if you use a thread safe connection manager:

http://hc.apache.org/httpclient-legacy/threading.html

Technically, it is possible to use multiple instances in parallel, but then don't mix them up and use them independently!

Upvotes: 5

Related Questions