Skip to content

Instantly share code, notes, and snippets.

@Yatharth0045
Last active April 7, 2019 16:04
Show Gist options
  • Save Yatharth0045/0ffba7b2fef6bd2c9186d4829e376a4b to your computer and use it in GitHub Desktop.
Save Yatharth0045/0ffba7b2fef6bd2c9186d4829e376a4b to your computer and use it in GitHub Desktop.
This program is to show the use of theRun() method of completablefuture
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
class Test {
public static void main(String[] args) throws ExecutionException, InterruptedException {
CompletableFuture<Integer> completableFuture = CompletableFuture.supplyAsync(() -> (int) (Math.random() * 10));
CompletableFuture<Void> voidCompletableFuture = completableFuture.thenRun(() -> {
System.out.println("Random number is generated.");
});
voidCompletableFuture.get();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment