rakib
rakib

Reputation: 131

Multiple execution by apache httpclient

So here is the thing, I need to access a very busy site which i cannot access with only a single request.

So what I want is to make multiple requests for a same web-address using Apache HttpClient or other good library of java and wait for a successful response form the site. Once a request get a successful response all other request in the thread need to terminated immediately.

How can I do it? Also if there is other good library available for the task please let me know.

Upvotes: 1

Views: 3133

Answers (1)

Anton Krosnev
Anton Krosnev

Reputation: 4132

My suggestion is to use single thread and retry if some error occurs. This way you will not flood the busy site. This will not be much slower, because if the server's busy, making more requests will not give you any advantage. If you decide to use multiple threads anyway (use 2), all the threads needs to share the same HTTP client:

CloseableHttpClient httpclient = createDefault();

When you receive successful response you will have to call

 httpclient.close();

and stop all the threads. The close() will terminate all the connections (active and inactive).

Upvotes: 2

Related Questions