Java 8 Completablefuture Shallow entry

Source: Internet
Author: User

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 8CompletableFuturefunction, you can simply use it to implement asynchronous methods. AlthoughCompletableFutureRealized theFutureinterface, but most of its methods derive fromCompletionStage, so also the Richter substitution, withFutureTo referenceCompletableFutureThe example is very far-fetched; This is also why the type of direct exposure playframework since 2.5 isCompletionStageInstead of the other two.

As the name implies, Completablefuture represents a future after the completion of what to do, specifically:

    1. Perform the action after the future completes, or seek the value of the next future. Then ...

    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.