From Simpleaynctaskexecutor to Listenablefuturetask

Source: Internet
Author: User

Spring asyncexecutor FeedbackIntroductory

Originally wanted to see spring on the main content of Async&sync Taskexecutor, looking at the discovery Listenabletaskexecutor is also very interesting, Futuretask is also very interesting, and finally found that This code design is really interesting.

Simpleasynctaskexecutorstructure Diagram

To understand Simpleasynctaskexecutor, let's take a look at its class diagram and inheritance relationship.

What you want to say here is that every time a user submits a new task to simpleasynctaskexecutor, it starts a new thread to respond to the customer request and automatically destroys it after processing the customer request, which means that it does not provide the thread pool functionality, such as

If you want to implement the function of the thread pool, you can implement the Customizablethreadcreator to get the necessary function, this is not the point, the focus is to find its monitoring future API, suddenly want to find the principle:

Listenablefuturetask

Each listenablefuturetask is both a task and a future, the key is that it aggregates a strategy: listenablefuturecallbackregistry

Listenablefuturetask to callback Listenablefuturecallbackregistry's Onsuccess or OnFailure method by overriding the done method of Futuretask

Futuretask

Futuretask Template The Done method, left to the successor to implement, very flexible, where the JDK source code The queueingfuture is aggregated in the executorcompletionservice :

Executorcompletionservice can asynchronously handle tasks that do not need to be ordered, and ultimately get task execution results from a queue.

Flowchart of Realization Idea

Personally feel that the above figure and the notes in the picture are very clear.

From Simpleaynctaskexecutor to Listenablefuturetask

Related Article

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.