I have a multi threading problem where there are bunch of requests which will take varied time for processing. I want to get response of all the requests and consume the responses.
My plan is to use CompletableFuture but not able to come up with how to code it. I created a mock up using ExecutorService and here too I am not sure how to handle the future result.
Would it be better to wait for a response with blocking call such as get() or should I use a while loop and loop around until all results are either done or canceled?
Here is the current mock up :
Would like to get advice on:
1) handling future result in current case.
2) if I use CompletableFuture, what should be the approach to this problem ?
You could do that. I'm not sure what the difference would be if you used CompletableFuture instead but perhaps you could explain what you thought the difference would be when you planned to use it.
Thanks for the response. I updated my function with what you provided, hope this is how we should be handling the future results.
Coming back to by intention of using CompletableFuture, well I wanted to create sort of workflow pipeline and handle the result from all requests asynchronously.
But as I need the list of responses to process those further, that part is little murky for now.
Here is an incomplete code which I am trying to work out.