Java.util.concurrent: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 29: Line 29:
A Future represents the result of an asynchronous computation. Future instances are returned by [[Java.util.concurrent_Executors#future|executors]] upon task submission.  
A Future represents the result of an asynchronous computation. Future instances are returned by [[Java.util.concurrent_Executors#future|executors]] upon task submission.  


Having access to the Future instance,e the caller may check if the computation is complete, wait for its completion, and retrieve the result of the computation.  
Having access to the Future instance, the caller may check if the computation is complete, wait for its completion, and retrieve the result of the computation.  


The result of the computation is retrieved with <tt>Future.get()</tt>, only when the computation has completed. The call will block if the computation is not ready.
The result of the computation is retrieved with <tt>Future.get()</tt>, only when the computation has completed. The call will block if the computation is not ready.


The computation can be cancelled <tt>Future.cacel()</tt>. Once a computation has completed, the computation cannot be cancelled. Additional methods are provided to determine if the task completed normally or was cancelled.   
The computation can be cancelled <tt>Future.cancel()</tt>. Once a computation has completed, the computation cannot be cancelled. Additional methods are provided to determine if the task completed normally or was cancelled.   


It is possible to use a Future with the only purpose of canceling the task, without any interest in the result. If that is the case, declare types of the form <tt>Future<?></tt> and return null as a result of the underlying task.
It is possible to use a Future with the only purpose of canceling the task, without any interest in the result. If that is the case, declare types of the form <tt>Future<?></tt> and return null as a result of the underlying task.


==Callable==
==Callable==

Revision as of 14:15, 14 June 2017



in process of being migrated from https://home.feodorov.com:9443/wiki/Wiki.jsp?page=JavaConcurrent

External

Internal

Overview

java.util.concurrent is a collection of utility classes to use for concurrent programming.

Subjects

General Concepts

Future

https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html

A Future represents the result of an asynchronous computation. Future instances are returned by executors upon task submission.

Having access to the Future instance, the caller may check if the computation is complete, wait for its completion, and retrieve the result of the computation.

The result of the computation is retrieved with Future.get(), only when the computation has completed. The call will block if the computation is not ready.

The computation can be cancelled Future.cancel(). Once a computation has completed, the computation cannot be cancelled. Additional methods are provided to determine if the task completed normally or was cancelled.

It is possible to use a Future with the only purpose of canceling the task, without any interest in the result. If that is the case, declare types of the form Future<?> and return null as a result of the underlying task.

Callable