I am using an external library that has the code from below. I am sending a lot of commands and am interesed in the result for statistics to check how many calls failed and how many succeeded
public Future<CommandResult> sendCommand(Command command) {
return command.execute();
}
CommandResult can be success or failure
However, if I use client.sendCommand(command).get();
then, I am waiting for the result synchronously, meanwhile the app is being blocked.
I would like to check only later (after 30 seconds which calls succeded and which failed). I am guaranteed to get an answer in 10 seconds. The problem is that the app waits for the computation to complete, and then retrieves its result.
I was thinking about this approach based on the answers:
List<Future< CommandResult >> futures = new ArrayList<>();
for(Command command: commands) {
futures.add(client.sendCommand(command));
}
//in a scheduler, 30+ seconds later
for (Future<Boolean> future : futures) {
saveResult(future.get());
}