I don\'t understand how to use AsyncRestTemplate
effectively for making external service calls. For the code below:
class Foo {
public void doS
You might want to use CompletableFuture
class (javadoc).
Transform your calls into CompletableFuture
. For instance.
final CompletableFuture> cf = CompletableFuture.supplyAsync(() -> {
try {
return future.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
});
Next call CompletableFuture::allOf
method with your 3 newly created completable futures.
Call join()
method on the result. After the resulting completable future is resolved you can get the results from each separate completable future you've created on step 3.