Skip to content

Instantly share code, notes, and snippets.

@tomas-langer
Last active September 12, 2022 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomas-langer/c39a9e8e5f530c50ac01ae17ad3ba160 to your computer and use it in GitHub Desktop.
Save tomas-langer/c39a9e8e5f530c50ac01ae17ad3ba160 to your computer and use it in GitHub Desktop.
Medium-Nima-Blocking-Prallel
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