從ThreadPoolExecutor類的代碼可以知道,ThreadPoolExecutor 繼承了AbstractExecutorService,我們來看一下AbstractExecutorService的實現:
public abstract class AbstractExecutorService implements ExecutorService {
protected
protected
public Future> submit(Runnable task) {};
public
public
private
boolean timed, long nanos)
throws InterruptedException, ExecutionException, TimeoutException {
};
public
throws InterruptedException, ExecutionException {
};
public
long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
};
public
throws InterruptedException {
};
public
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(Runnable task);
throws InterruptedException;
long timeout, TimeUnit unit)
throws InterruptedException;
throws InterruptedException, ExecutionException;
long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException;
}
而ExecutorService又是繼承了Executor接口,我們看一下Executor接口的實現:
public interface Executor {
void execute(Runnable command);
}
到這裡,大家應該明白了ThreadPoolExecutor、AbstractExecutorService、ExecutorService和Executor幾個之間的關係了。
後續內容更加精彩,喜歡就點擊關注哦謝謝!
閱讀更多 Java雜談 的文章