hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Check Peck <comptechge...@gmail.com>
Subject using apache httpclient efficiently in multithreaded environment
Date Thu, 12 May 2016 20:17:17 GMT
I have a library which is being used by customer and they are passing
DataRequest object which has userid, various timeouts and some other fields
in it. Now I use this DataRequest object to make a URL and then I make an
HTTP call using Apache HttpClient and my service returns back a JSON
response which I use it to make a DataResponse object and return this
DataResponse object back to them.

Below is my DataClient class used by customer by passing DataRequest object
to it.


And here is DataFetcherTask class:


Customer within our company will use my library like this as shown below by
using my factory in their code base -

    // if they are calling getSyncData() method
    DataResponse response =

    // and if they want to call getAsyncData() method
    Future<DataResponse> response =

I am implementing "sync call as async + waiting" since I want to throttle
them with the number of threads otherwise they can bombard our service
without any control. My library will be used by lot of customers within our
company and their applications won't ever shutdown, they will keep running
always. The only thing will happen is their machines will get restarted,
that's all.

Is this the right way to use Apache HttpClient in production in
multithreaded environment? Or there is any better/efficient way?

I have to use various timeout values present in my DataRequest class in my
Apache HttpClient calls so that's  why I am creating RequestConfig and
using it in my call method. I have simplified the code so that idea gets
clear what I am trying to do.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message