Java Future 线程接口

时间:2021-09-07
本文章向大家介绍Java Future 线程接口,主要包括Java Future 线程接口使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

源码展示

package java.util.concurrent;

/**
 * A Future represents the result of an asynchronous computation.
 */
public interface Future<V> {

    /**
     * Attempts to cancel execution of this task.  
     */
    boolean cancel(boolean mayInterruptIfRunning);

    /**
     * Returns true if this task was cancelled before it completed normally.
     */
    boolean isCancelled();

    /**
     * Returns true if this task completed.
     */
    boolean isDone();

    /**
     * Waits if necessary for the computation to complete, and then
     * retrieves its result.
     */
    V get() throws InterruptedException, ExecutionException;

    /**
     * Waits if necessary for at most the given time for the computation
     * to complete, and then retrieves its result, if available.
     *
     * @param timeout the maximum time to wait
     * @param unit the time unit of the timeout argument
     */
    V get(long timeout, TimeUnit unit)
        throws InterruptedException, ExecutionException, TimeoutException;
}

原文地址:https://www.cnblogs.com/feiqiangsheng/p/15237458.html