Created
April 3, 2019 01:29
-
-
Save Yatharth0045/89575afa63dbcd4fcdbea1788f8a8e15 to your computer and use it in GitHub Desktop.
An example to show runAsync 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 completableFuture = CompletableFuture.supplyAsync(() -> { | |
System.out.println(Thread.currentThread().getName() + " Runnable Call to be executed by another thread"); | |
return "Result of the asynchronous computation"; | |
}); | |
System.out.println(Thread.currentThread().getName() + " Main Thread"); | |
System.out.println(completableFuture.get()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment