【Tech-Android-Other】Android中的Future

public interface

Future

java.util.concurrent.Future<V>
Known Indirect Subclasses
FutureTask<V>A cancellable asynchronous computation. 
RunnableFuture<V>A Future that isRunnable
RunnableScheduledFuture<V>A ScheduledFuture that isRunnable
ScheduledFuture<V>A delayed result-bearing action that can be cancelled. 

Class Overview

A Future represents the result of an asynchronous computation. Methods are provided to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation. The result can only be retrieved using methodget when the computation has completed, blocking if necessary until it is ready. Cancellation is performed by thecancel method. Additional methods are provided to determine if the task completed normally or was cancelled. Once a computation has completed, the computation cannot be cancelled. If you would like to use aFuture for the sake of cancellability but not provide a usable result, you can declare types of the formFuture<?> and return null as a result of the underlying task.

 
 
 
   这个类能获取异步预算的结果。它的方法可以提供我们去检查如果运算已经完成了,去等待它运算,去得到他的运算 结果。
   这个运算结果仅仅在运算结束后通过get的方法获得,这个方法会阻塞程序。取消的运算是通过cancle这个方法呈现的。额外的方法提供了判断如果这个任务已经正常的完成或者已经被取消了。
   一旦一个运算操作已经完成,这个运算操作就不能被取消。如果想去使用一个Future的cncle功能,但又没有提供一个可用的结果,你可以声明一个类型通过Future<T> 和返回一个null值作为一个已经没有效力的任务。
 
 
 
 
public class

FutureTask

extends Object
implements RunnableFuture<V>
 
 

Class Overview

A cancellable asynchronous computation. This class provides a base implementation ofFuture, with methods to start and cancel a computation, query to see if the computation is complete, and retrieve the result of the computation. The result can only be retrieved when the computation has completed; the get method will block if the computation has not yet completed. Once the computation has completed, the computation cannot be restarted or cancelled.

A FutureTask can be used to wrap a Callable orRunnable object. BecauseFutureTask implements Runnable, a FutureTask can be submitted to anExecutor for execution.

In addition to serving as a standalone class, this class provides protected functionality that may be useful when creating customized task classes.

 

   一个可取消的异步运算,这个类实现了Fututre的借口,可以开始和取消一个运算操作,判断这个操作是否已经完成了,和重新得到运算操作的结果。运算的结果仅仅在运算结束完成后被恢复,get的方法将会阻塞程序,如果这个运算操作还没有完成的话。一旦运算操作完成了,这个操作就不能重新开始或者取消了。

 

   这个类过去常常用于包装一个Callable or Runnable 类的。因为FutureTask实现了runnable借口,一个FutureTask可以实现线程池中的execution方法。

   除了是一个单独的类之外,这个类还提供了可能有之用途定制任务classed的保护功能.

 

 

 

 
 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值