Java multithreaded (11) mode-future

Source: Internet
Author: User
Future

Gets the thread result when it is needed.

Applicable environment

The caller delegates the task that gets the result to an intermediate class, where both the caller and the task thread hold the class instance.

When the caller needs to get the result, the method of the intermediate class is called, and if the result is not reached at this time, it can be waited on the intermediate class instance or returned directly.

When the task thread finishes executing, the service provider writes the result to the intermediate class instance, and notifies the thread waiting on the class instance that the result can be obtained.

Sample Intermediate Class

Synchronize settings, get results. When you get the result, wait if you don't arrive (you can also return a signal to let the caller handle the wait by itself.) )

Called by

When a request is sent and the result is obtained, if the intermediate class does not provide a wait, it needs to handle whether to wait or fail.

Service Provider

Receives the request, creates an intermediate class instance, gives the intermediate class instance to the execution thread, and returns.

This article is from the Java Technology Stack notes blog, so be sure to keep this source http://stroll.blog.51cto.com/11038467/1859219

Java multithreaded (11) mode-future

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.