ExecutorService接口的基本方法
先来一段Exector,ExectorService接口的集成体系
public interface Executor{
??? void execute(Runnable command);
}
public interface ExectorService implements Executor{
??? void shutdown();
??? List<Runnable> shutdownNow();
??? boolean isShutdown();
??? boolean isTerminated();
?
? ? //
??? boolean awaitTermination(long timeout, TimeUnit unit)
??????? throws InterruptedException;
??? <T> Future<T> submit(Callable<T> task);
???
}
?
线程池Executor是异步的执行任务,因此任何时刻不能够直接获取提交的任务的状态。这些任务有可能已经完成,也有可能正在执行或者还在排队等待执行。因此关闭线程池可能出现一下几种情况:
平缓关闭(shutdown):已经启动的任务全部执行完毕,同时不再接受新的任务
立即关闭(shutdownNow):取消所有正在执行和未执行的任务
?
?
进入
?
?
awaitTermination(long?timeout, TimeUnit?unit)
?
?
?
?