共同学习Java源代码-多线程与并发-Future、RunnableFuture接口

来源:互联网 发布:美好时光只在昨日 知乎 编辑:程序博客网 时间:2024/06/10 02:42

这是进行异步计算的接口 

public interface Future<V>


    boolean cancel(boolean mayInterruptIfRunning);

这个方法是取消执行这个异步任务的方法 参数为true代表任务可以被打断 


    boolean isCancelled();

这个方法是判断这个任务是否被取消的方法 


    boolean isDone();

这个方法是判断这个任务是否完成的方法

  

   V get() throws InterruptedException, ExecutionException;

这个方法是获取执行结果的方法 


V get(long timeout, TimeUnit unit)
        throws InterruptedException, ExecutionException, TimeoutException;

这个方法是根据截止时间获取执行结果的方法


public interface RunnableFuture<V> extends Runnable, Future<V> {

    void run();
}

RunnableFuture接口继承自Runnable和Future 就一个run方法

阅读全文
0 0
原创粉丝点击