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.

https://gist.github.com/TechGeeky/250be2d9cdef3fa5107a17058a265d4c

And here is DataFetcherTask class:

https://gist.github.com/TechGeeky/c1b21025e0f81d222b792dedac0a817d

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 =
DataClientFactory.getInstance().getSyncData(key);

    // and if they want to call getAsyncData() method
    Future<DataResponse> response =
DataClientFactory.getInstance().getAsyncData(key);

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.

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