Last active
January 16, 2019 07:57
-
-
Save dfparker2002/477b78d57909ba26adcb56bbf9bb28f0 to your computer and use it in GitHub Desktop.
CompletableFuture usage
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
/* | |
src: https://github.com/eugenp/tutorials/blob/2e2f3bc4a95f83b91188b5ea7ee75e7913d3fe03/libraries/src/main/java/com/baeldung/loom/AsyncThreads.java | |
Adobe HTTP Client ex: https://stackoverflow.com/questions/37434906/how-do-i-get-a-completablefuturet-from-an-async-http-client-request#37437643 | |
CompletableFuture<Response> f = asyncHttpClient | |
.prepareGet("http://api.football-data.org/v1/soccerseasons/398") | |
.execute() | |
.toCompletableFuture(); | |
*/ | |
import java.util.concurrent.CompletableFuture; | |
import java.util.concurrent.ExecutionException; | |
public class AsyncThreads { | |
public static void main(String[] args) throws ExecutionException, InterruptedException { | |
CompletableFuture<Void> cf = CompletableFuture.runAsync(() -> { | |
System.out.println("Hello " + Thread.currentThread().getName()); | |
}); | |
cf.thenRun(() -> { | |
System.out.println("World " + Thread.currentThread().getName()); | |
}); | |
cf.get(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment