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