Created
September 18, 2022 15:23
-
-
Save viveknaskar/c1c8eae45fa3999b0947bfc884edcf10 to your computer and use it in GitHub Desktop.
Simplest example of CompletableFuture
This file contains 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; | |
public class SimpleCompletableFutureExample { | |
public static void main(String[] args) { | |
CompletableFuture<String> completableFuture = new CompletableFuture<>(); | |
try { | |
// we can get the result using CompletableFuture.get() | |
completableFuture.get(); | |
// we can force complete a completable future | |
completableFuture.complete("some dummy data from Future"); | |
} catch (InterruptedException | ExecutionException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment