CompletableFuture API Improvements


CompletableFuture class was introduced in Java 8 to represent the long run which may be completed by setting its worth and standing explicity. It will be used as java.util.concurrent.CompletionStage. It supports dependent functions and actions that got triggered upon the future's completion. In java nine CompletableFuture API has been increased additional. Following area unit the relevant changes done to the API.
  • Support for delays and timeouts.
  • Improved support for subclassing.
  • New factory methods added.

Support for delays and timeouts

public CompletableFuture completeOnTimeout(T price, long timeout, TimeUnit unit)
This 8 method completes this CompletableFuture with the given price if not otherwise completed before the given timeout.
    public CompletableFuture orTimeout(long timeout, TimeUnit unit)

This 8 method exceptionally completes this CompletableFuture with a TimeoutException if not otherwise completed before the given timeout. Improved support for subclassing

Improved support for subclassing

public fiduciary defaultExecutor()
It returns the default fiduciary used for async ways that don't specify an fiduciary. This method could also be overridden in subclasses to come an fiduciary to produce one freelance thread as minimum.
public  CompletableFuture newIncompleteFuture()
Returns a replacement incomplete CompletableFuture of the sort to be came by a CompletionStage method. Subclasses of CompletableFuture class ought to override this method to come an instance of an equivalent class as this CompletableFuture. The default implementation returns an instance of sophistication CompletableFuture.





javacodegeeks is optimized for learning.© javacodegeeks .
All Right Reserved and you agree to have read and accepted our term and condition