I use org.apache.http.client.HttpClient. I have a question that concerns the use of this class.
Should I create a new HttpClient
per request (e.g. because it is a light object) or it is better to use a unique instance per many http requests (e.g., because create/delete is expensive)?
If only one instance of HttpClient
must be used, is HttpClient
thread safe (e.g., it can handle many http requests at the same time) or it is preferable in this case to create a pool of HttpClient
s?
Actually, I create a new HttpClient per request. I suspect that I must create a unique instance to be closed at the end of the use of my application by using getConnectionManager().shutdown()
, but I don't know if I can maintain Thread-based parallelism.
The DefaultHttpClient
is marked with the @ThreadSafe
annotation so yes you can use it in a Thread safe manner. The performance documentation from HTTPClient also actively recommends using a single instance where possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With