2.Future

作者: 元代码 | 来源:发表于2017-09-22 11:27 被阅读0次

    Future接口,顾名思义标的一个任务的未来:要么执行完成要么被取消
    方法说明:
    1.boolean cancel(boolean mayInterruptIfRunning);
    Attempts to cancel execution of this task. This attempt will
    fail if the task has already completed, has already been cancelled,
    or could not be cancelled for some other reason
    取消执行任务。如果任务已经执行完成,或者已经取消,或者由于其他原因不能被取消,则取消失败
    通过参数设置是否打断任务的执行
    2.boolean isCancelled();
    if this task was cancelled before it completed normally
    查看正常结束之前是否被取消
    3.boolean isDone();
    if this task completed
    查看任务是否已结束
    4.V get() throws InterruptedException, ExecutionException;
    Waits if necessary for the computation to complete, and then
    retrieves its result
    等到任务执行结束(如需要等待),然后返回结果
    5.V get(long timeout, TimeUnit unit)
    throws InterruptedException, ExecutionException, TimeoutException;
    Waits if necessary for at most the given time for the computation
    to complete, and then retrieves its result, if available.
    在指定的等待时间内让任务执行(如需要等待),如果有结果就返回

    相关文章

      网友评论

          本文标题:2.Future

          本文链接:https://www.haomeiwen.com/subject/cagxextx.html