線程常用接口

java.lang.Runnable
public interface Runnable {
        public abstract void run();
}

java.util.concurrent.Callable
public interface Callable<V> {
    V call() throws Exception;
}

java.util.concurrent.Future
public interface Future<V> {
        boolean cancel(boolean mayInterruptIfRunning);  //嘗試取消當前任務
        boolean isCancelled(); //判斷當前任務是否取消
        boolean isDone(); //當前任務是否完成
        V get() throws InterruptedException, ExecutionException; //阻塞直到獲得結果
        V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException;
}

java.util.concurrent.RunnableFuture
public interface RunnableFuture<V> extends Runnable, Future<V> {
    void run();
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章