Java 1.5 has a future, it is a big step forward, and then Java 1.8 to join a new implementation of the Completablefuture, from this thread and thread can be a pleasant conversation. Coordination between the first two threads I used an Object.wait()
Andnotify()
, Thread'sjoin()
method, which is a very low-level API, whether many Java programs are not aware of their existence, or do not use them at all.
If it is simple to wait for all threads to complete a countdownlatch that can use Java 1.5, here is an introduction to the Countdownlatch coordination thread, which is the waitAll (threads) function implemented. and the Java 8CompletableFuture
function, you can simply use it to implement asynchronous methods. AlthoughCompletableFuture
Realized theFuture
interface, but most of its methods derive fromCompletionStage
, so also the Richter substitution, withFuture
To referenceCompletableFuture
The example is very far-fetched; This is also why the type of direct exposure playframework since 2.5 isCompletionStage
Instead of the other two.
As the name implies, Completablefuture represents a future after the completion of what to do, specifically:
Perform the action after the future completes, or seek the value of the next future. Then ...
Coordination of multiple future; At the same time to complete how, one of the finished how. AllOf, AnyOf
Sometimes you can think of the future as a thread that corresponds to one by one. Read the full text >>
Java 8 Completablefuture Shallow entry