user1170330 user1170330 - 1 year ago 133
Java Question

Difference between Future and Promise

What's the difference between


They both act like a placeholder for future results, but where is the main difference?

Answer Source

According to this discussion, Promise has finally been called CompletableFuture for inclusion in Java 8, and its javadoc explains:

A Future that may be explicitly completed (setting its value and status), and may be used as a CompletionStage, supporting dependent functions and actions that trigger upon its completion.

An example is also given on the list:

f.then((s -> aStringFunction(s)).thenAsync(s -> ...);

Note that the final API is slightly different but allows similar asynchronous execution:

CompletableFuture<String> f = ...;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download