Last active
April 7, 2019 16:11
-
-
Save Yatharth0045/3245a8a67fcbb019dbc4a34769dae554 to your computer and use it in GitHub Desktop.
This program is to show the use of thenAccept() method of completablefuture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.thenAccept(System.out::println); | |
voidCompletableFuture.get(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment