从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几个之间的关系了。
后续内容更加精彩,喜欢就点击关注哦谢谢!