Differences between Listenablefuture vs Completablefuture in java

/
0 Comments
 "ListenableFuture" and "CompletableFuture" are both classes in the Java Concurrency API. They are used for asynchronous programming and handling parallelism in Java applications.

The key difference between the two is that "ListenableFuture" is a subclass of "Future" that provides a mechanism for registering callbacks to be notified when a computation is complete, while "CompletableFuture" extends "Future" and provides the ability to complete a computation from another thread.  

In other words, "ListenableFuture" allows you to add a callback that will be executed when the future is complete, whereas "CompletableFuture" allows you to programmatically complete a future and provide a result.

Here's a brief summary of the main differences:

"ListenableFuture" is a subclass of "Future" that allows you to register a callback to be executed when the future is complete.

"CompletableFuture" is a subclass of "Future" that allows you to programmatically complete a future and provide a result.

"ListenableFuture" is a passive way of handling futures, while "CompletableFuture" is an active way of handling futures."CompletableFuture" provides a rich set of methods for composing, transforming, and combining Futures, whereas "ListenableFuture" is more focused on being notified when a future is complete.


You may also like

No comments: