K
K
kidar22016-02-05 11:02:51
Java
kidar2, 2016-02-05 11:02:51

How to send N get requests in parallel and wait for all responses?

You need to make a bunch of requests to a third-party service, and consistently it takes a long time.
Is there anything else besides separate threads? Ideally it would be like js - asynchronously.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kidar2, 2016-02-05
@kidar2

This seems to be true:

urls.parallelStream().forEach(u ->
    {
      LOG.debug("Page: " + u + usersResponse.pages.total_pages);
      try
      {
        String r = <Send getRequest>
      }
      catch (Exception e)
      {
        LOG.error(e);
      }
    });

A
aol-nnov, 2016-02-05
@aol-nnov

RxJava + OkHttp? )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question