從ThreadPoolExecutor類的代碼可以知道,ThreadPoolExecutor 繼承了AbstractExecutorService,我們來看一下AbstractExecutorService的實現:
public abstract class AbstractExecutorService implements ExecutorService {
protected RunnableFuture newTaskFor(Runnable runnable, T value) { };
protected RunnableFuture newTaskFor(Callable callable) { };
public Future> submit(Runnable task) {};
public Future submit(Runnable task, T result) { };
public Future submit(Callable task) { };
private T doInvokeAny(Collection extends Callable> tasks,
boolean timed, long nanos)
throws InterruptedException, ExecutionException, TimeoutException {
};
public T invokeAny(Collection extends Callable> tasks)
throws InterruptedException, ExecutionException {
};
public T invokeAny(Collection extends Callable> tasks,
long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
};
public List<future>> invokeAll(Collection extends Callable> tasks)/<future>
throws InterruptedException {
};
public List<future>> invokeAll(Collection extends Callable> tasks,/<future>
long timeout, TimeUnit unit)
throws InterruptedException {
};
}
AbstractExecutorService是一個抽象類,它實現了ExecutorService接口。
我們接著看ExecutorService接口的實現:
public interface ExecutorService extends Executor {
void shutdown();
boolean isShutdown();
boolean isTerminated();
boolean awaitTermination(long timeout, TimeUnit unit)
throws InterruptedException;
Future submit(Callable task);
Future submit(Runnable task, T result);
Future> submit(Runnable task);
List<future>> invokeAll(Collection extends Callable> tasks)/<future>
throws InterruptedException;
List<future>> invokeAll(Collection extends Callable> tasks,/<future>
long timeout, TimeUnit unit)
throws InterruptedException;
T invokeAny(Collection extends Callable> tasks)
throws InterruptedException, ExecutionException;
T invokeAny(Collection extends Callable> tasks,
long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException;
}
而ExecutorService又是繼承了Executor接口,我們看一下Executor接口的實現:
public interface Executor {
void execute(Runnable command);
}
到這裡,大家應該明白了ThreadPoolExecutor、AbstractExecutorService、ExecutorService和Executor幾個之間的關係了。
後續內容更加精彩,喜歡就點擊關注哦謝謝!