filmov
tv
Java Cookbook - Working with Completablefuture in Java and REST API

Показать описание
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.
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.
Комментарии