Skip to content

Instantly share code, notes, and snippets.

@dfparker2002
Last active January 16, 2019 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfparker2002/477b78d57909ba26adcb56bbf9bb28f0 to your computer and use it in GitHub Desktop.
Save dfparker2002/477b78d57909ba26adcb56bbf9bb28f0 to your computer and use it in GitHub Desktop.
CompletableFuture usage
/*
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