Understanding Java Future

 

Understanding Java Future and Completable Future


Future is a simple representation of an asynchronous task. It is a type that holds the result from a task that may not have finished yet but may be some time in future.

The Java future defined an interface and developer had to implement a concrete class in order to provide own functionality. However Completable Future is a concrete type that implements that Future interface which is required to build a simple asynchronous application.

The main idea is that we can create instances of CompletableFuture<T> and the return type represents the object that is created in an uncompleted form.

Later on if any thread get reference to that uncompleted Future , it can complete it and can provide a value which is called Fulfilling a Future.

The Completable Future is immediately visible to the all threads that are blocked on get() call. After completion any further calls to get() are ignored.

The CompletableFuture can not cause different thread to see different values. There is no possibility of another thread to see the inconsistent state of a future.

Post a Comment

0 Comments