-
-
Save tomas-langer/c39a9e8e5f530c50ac01ae17ad3ba160 to your computer and use it in GitHub Desktop.
Medium-Nima-Blocking-Prallel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> responses = new LinkedList<>(); | |
// list of tasks to be executed in parallel | |
List<Callable<String>> callables = new LinkedList<>(); | |
for (int i = 0; i < count; i++) { | |
callables.add(() -> client.get().request(String.class)); | |
} | |
// execute all tasks (blocking operation) | |
for (var future : EXECUTOR.invokeAll(callables)) { | |
responses.add(future.get()); | |
} | |
// send it | |
res.send("Combined results: " + responses); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment