CompletableFuture
CompletableFuture is an implementation of the Future and CompletionState interface and is used for asynchronous programming in java.
runAsync()
This method run background task asynchronously and don't want to return anything from the task.
supplyAsync()
This method run background task asynchronously and return the result.
CompletableFuture callbacks
thenApply()
This callback will process and transform the result of the CompletableFuture and return it result.
thenAccept() and thenRun()
If you don't want to return anything from your callback function you can use these methods.
Combining CompletableFutures together
thenCombine()
This method is use to combine two Futures where one future is dependent on the other.
thenCompose()
This method is use to bine two Futures to run independently and do something after both are complete.
allOf()
This method is used when you have a list of independent futures that you want to run in parallel and do something after all of them are complete.
anyOf()
This method will return a new CompletableFuture that is completed first.
Exception handling
exceptionally()
This callback give you a change to recover from errors generated from the original Future.
handle()
This callback is more generic method to handle an exception.
On this page of the site you can watch the video online Java Cookbook - Working with Completablefuture in Java and REST API with a duration of hours minute second in good quality, which was uploaded by the user WJ Prajumsook 24 December 2021, share the link with friends and acquaintances, this video has already been watched 391 times on youtube and it was liked by 11 viewers. Enjoy your viewing!