Java RunnableFuture源码总结 RunnableFuture源码注释翻译和解析中英文对照版

版本
JDK8(JDK1.8)

RunnableFuture接口源码重点
1.RunnableFuture接口继承自Runnable接口和Future接口,重写Runnable的run()方法,在run方法运行中为Future设置运行结果,在run()方法运行后,可以通过get()方法获取结果

Runnable源码可以看我这篇文章 Runnable
Future源码可以看我这篇文章 Future

2.RunnableFuture接口由于继承Future自然就可以取消任务,以及拥有判断任务是否完成和取消的方法

3.RunnableFuture由于继承Runable接口可以和Thread结合使用,也可以和Executor.execute(Runnable)结合使用

Executor源码可以看我这篇文章 Executor

RunnableFuture接口源码

package java.util.concurrent;

/**
 * A {@link Future} that is {@link Runnable}. Successful execution of
 * the {@code run} method causes completion of the {@code Future}
 * and allows access to its results.
 * 是Runnable的Future。
 * run方法的成功执行导致Future的完成,并允许访问其结果。
 * 
 * @see FutureTask
 * @see Executor
 * @since 1.6
 * @author Doug Lea
 * @param <V> The result type returned by this Future's {@code get} method
 *              此Future的get方法返回的结果类型
 */
public interface RunnableFuture<V> extends Runnable, Future<V> {
    /**
     * Sets this Future to the result of its computation
     * unless it has been cancelled.
     * 将此Future设置为其计算结果,除非已取消。
     */
    void run();
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lolxxs

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值