前一篇文章画了一张巨大的类图,但是只重点分析了NioEventLoopGroup的继承层次,这篇文章来看看NioEventLoop的继承层次。
从Executor接口说起
public interface Executor {
void execute(Runnable command);
}
Executor接口只有一个方法,用来执行一个命令。但是什么时候执行,在哪个线程里执行,得看具体的实现。
ExecutorService接口
ExecutorService接口扩展了Executor接口,添加了两组方法,一组用来终止Executor的执行:
void shutdown();
List<Runnable> shutdownNow();
boolean isShutdown();
boolean isTerminated();
boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException;
另一组扩展Executor的执行能力,让它可以提交和执行Callable任务:
<T> Future<T> submit(Callable<T> task);
<T> Future<T> submit(Runnable task, T result);
Future<?> submit(Runnable task);
<T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException;
<T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException;
<T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException;
<T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException;
ScheduledExecutorService接口
ScheduledExecutorService接口扩展ExecutorService接口,添加了调度能力: