- 所有超级接口:
AutoCloseable,Executor,ExecutorService,IExecutor,IExecutorService,IScheduledExecutorService,Iterable<EventLoop>,ScheduledExecutorService
- 所有已知子接口:
EventLoop,FixedEventLoopGroup
事件循环线程组,它管理着一组
2.
EventLoop。
它的本质是容器,它主要负责管理持有的EventLoop的生命周期。
时序约定
1.EventLoopGroup代表着一组线程,不对任务的执行时序提供任何保证,用户只能通过工具自行协调。2.
Executor.execute(Runnable)IExecutorService.submit(Callable)系列方法的时序等同于schedule(task, 0, TimeUnit.SECONDS)
Q: 为什么在接口层不提供严格的时序约定?
A: 如果在接口层定义了严格的时序约定,实现类就会受到限制。
1.时序很重要,在提供并发组件时应该详细的说明时序约定,否则用户将无所措手足。
2.EventLoopGroup也可以有自己的线程 - 一种常见的情况是Group是一个监控线程。
- 作者:
- wjybxx date 2023/4/7
-
方法概要
修饰符和类型方法说明booleanawaitTermination(long timeout, TimeUnit unit) 等待EventLoopGroup进入终止状态 等同于在terminationFuture()进行阻塞操作。boolean查询EventLoopGroup是否处于关闭状态。boolean查询EventLoopGroup是否处于正在关闭状态。boolean是否已进入终止状态,一旦进入终止状态,表示生命周期真正结束。iterator()注意;如果包含不定数量的EventLoop,返回的是快照。select()选择一个EventLoop用于接下来的任务调度voidshutdown()请求关闭 ExecutorService,不再接收新的任务。JDK文档: 请求关闭 ExecutorService,尝试取消所有正在执行的任务,停止所有待执行的任务,并不再接收新的任务。IFuture<?> 返回等待线程终止的future。从接口继承的方法 java.util.concurrent.ExecutorService
close从接口继承的方法 cn.wjybxx.concurrent.IExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newPromise, submit, submit, submit, submit, submitAction, submitAction, submitAction, submitAction, submitFunc, submitFunc, submitFunc, submitFunc从接口继承的方法 cn.wjybxx.concurrent.IScheduledExecutorService
newScheduledPromise, schedule, schedule, schedule, scheduleAction, scheduleAtFixedRate, scheduleFunc, scheduleWithFixedDelay从接口继承的方法 java.lang.Iterable
forEach, spliterator
-
方法详细资料
-
select
选择一个EventLoop用于接下来的任务调度 -
iterator
注意;如果包含不定数量的EventLoop,返回的是快照。 -
isShuttingDown
boolean isShuttingDown()查询EventLoopGroup是否处于正在关闭状态。 正在关闭状态下,拒绝接收新任务,当执行完所有任务后,进入关闭状态。- 指定者:
isShuttingDown在接口中IExecutorService- 返回:
- 如果该
EventLoopGroup管理的所有EventLoop正在关闭或已关闭则返回true
-
isShutdown
boolean isShutdown()查询EventLoopGroup是否处于关闭状态。 关闭状态下,拒绝接收新任务,执行退出前的清理操作,执行完清理操作后,进入终止状态。- 指定者:
isShutdown在接口中ExecutorService- 指定者:
isShutdown在接口中IExecutorService- 返回:
- 如果已关闭,则返回true
-
isTerminated
boolean isTerminated()是否已进入终止状态,一旦进入终止状态,表示生命周期真正结束。- 指定者:
isTerminated在接口中ExecutorService- 指定者:
isTerminated在接口中IExecutorService- 返回:
- 如果已处于终止状态,则返回true
-
terminationFuture
IFuture<?> terminationFuture()- 指定者:
terminationFuture在接口中IExecutorService
-
awaitTermination
等待EventLoopGroup进入终止状态 等同于在terminationFuture()进行阻塞操作。- 指定者:
awaitTermination在接口中ExecutorService- 指定者:
awaitTermination在接口中IExecutorService- 参数:
timeout- 时间度量unit- 事件单位- 返回:
- 在方法返回前是否已进入终止状态
- 抛出:
InterruptedException- 如果在等待期间线程被中断,则抛出该异常。
-
shutdown
void shutdown()请求关闭 ExecutorService,不再接收新的任务。 ExecutorService在执行完现有任务后,进入关闭状态。 如果 ExecutorService 正在关闭,或已经关闭,则方法不产生任何效果。该方法会立即返回,如果想等待 ExecutorService 进入终止状态, 可以使用
awaitTermination(long, TimeUnit)或terminationFuture()进行等待- 指定者:
shutdown在接口中ExecutorService- 指定者:
shutdown在接口中IExecutorService
-
shutdownNow
JDK文档: 请求关闭 ExecutorService,尝试取消所有正在执行的任务,停止所有待执行的任务,并不再接收新的任务。 如果 ExecutorService 已经关闭,则方法不产生任何效果。该方法会立即返回,如果想等待 ExecutorService 进入终止状态,可以使用
IExecutorService.awaitTermination(long, TimeUnit)或IExecutorService.terminationFuture()进行等待。在EventLoop架构下不保证标准的实现,只保证尽快的关闭。基于以下原因:
- 1. 可能无法安全的获取所有的任务(EventLoop架构属于多生产者单消费者模型,会尽量的避免其它线程消费数据)
- 2. 剩余任务数可能过多
- 指定者:
shutdownNow在接口中ExecutorService- 指定者:
shutdownNow在接口中IExecutorService- 返回:
- may be empty。
-