Skip to content

Instantly share code, notes, and snippets.

@wkdalsgh192
Created July 15, 2021 12:04
Show Gist options
  • Save wkdalsgh192/c8866e1f61d6f305ef664e12d7506680 to your computer and use it in GitHub Desktop.
Save wkdalsgh192/c8866e1f61d6f305ef664e12d7506680 to your computer and use it in GitHub Desktop.
// when there is no return value
CompletableFuture<Void> future2 = CompletableFuture.runAsync(() -> {
System.out.println("Hello "+ Thread.currentThread().getName());
});
future2.get(); // get() should be called to execute the thread
// when there is a return value
CompletableFuture<String> future3 = CompletableFuture.supplyAsync(() -> {
System.out.println("HEllo " + Thread.currentThread().getName());
return "Hello";
});
System.out.println(future3.get());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment