We can use a CompletableFuture object with two main purposes:
- Wait for a value or an event that will be produced in future (creating an object and using the complete() and get() or join() methods).
- To organize a set of tasks to be executed in a determined order so one or more tasks won't start their execution until others have finished their execution.
In this example, we made both uses of the CompletableFuture class. First, we created an instance of this class and sent it as a parameter to a SeedGenerator task. This task uses the complete() method to send the calculated value, and the main() method uses the get() method to obtain the value. The get() method sleeps the current thread until CompletableFuture has been completed. ...