Follow these steps to implement the example:
- First, we're going to implement the auxiliary tasks we will use in the example. Create a class named SeedGenerator that implements the Runnable interface. It will have a CompletableFuture object as an attribute, and it will be initialized in the constructor of the class:
public class SeedGenerator implements Runnable { private CompletableFuture<Integer> resultCommunicator; public SeedGenerator (CompletableFuture<Integer> completable) { this.resultCommunicator=completable; }
- Then, implement the run() method. It will sleep the current thread for 5 seconds (to simulate a long operation), calculate a random number between 1 and 10, and then use the complete() method of the ...