EventExecutor hierarchy¶
The EventExecutor hierarchy forms the execution and scheduling backbone of Netty's asynchronous event handling model. It defines how tasks and events are processed, ranging from single-threaded executions to multi-threaded thread pools^[600-developer-big-data-netty-netty-eventloopgroup.md].
Core Components¶
The hierarchy consists of several key interfaces and implementations that build upon the standard Java concurrency model:
Base Executor¶
At the foundation lies the java.util.concurrent.Executor interface^[600-developer-big-data-netty-netty-eventloopgroup.md]. This Functional Interface defines a single method, execute(Runnable command), which decouples task submission from the mechanics of execution (such as thread creation or pooling)^[600-developer-big-data-netty-netty-eventloopgroup.md].
EventExecutor¶
EventExecutor is a core abstraction in the hierarchy^[600-developer-big-data-netty-netty-eventloopgroup.md]. It serves as a specialized Executor designed to handle the execution of tasks within the Netty framework.
Primary Implementations¶
The hierarchy is largely defined by specific implementations of the EventExecutor interface^[600-developer-big-data-netty-netty-eventloopgroup.md]:
- SingleThreadEventExecutor: An implementation that ensures all tasks are executed sequentially using a single thread^[600-developer-big-data-netty-netty-eventloopgroup.md].
- SingleThreadEventLoop: Extends
SingleThreadEventExecutorto add the capabilities of anEventLoop, typically used for I/O operations^[600-developer-big-data-netty-netty-eventloopgroup.md]. - EmbeddedEventLoop: An implementation designed for testing or embedded scenarios^[600-developer-big-data-netty-netty-eventloopgroup.md].
Grouped Executors¶
To manage multiple executors as a collection, the hierarchy introduces "Group" interfaces:
- EventExecutorGroup: A parent interface that manages a collection of
EventExecutors^[600-developer-big-data-netty-netty-eventloopgroup.md]. - EventLoopGroup: Extends
EventExecutorGroupto specifically handle channel registration and I/O operations^[600-developer-big-data-netty-netty-eventloopgroup.md].
Concrete Groups¶
The primary implementations of these groups in the hierarchy include^[600-developer-big-data-netty-netty-eventloopgroup.md]:
- NioEventLoopGroup: The standard group for NIO-based transport.
- MultithreadEventLoopGroup: An abstract base class for multi-threaded event loops.
- DefaultEventLoopGroup: A default implementation often used for non-I/O task execution.
Relationship to Standard Java Executors¶
The Netty hierarchy aligns with standard Java concurrency patterns but provides enhanced capabilities^[600-developer-big-data-netty-netty-eventloopgroup.md]. For example, MultithreadEventLoopGroup extends MultithreadEventExecutorGroup, mirroring the relationship between specific logic and generic thread management found in standard libraries^[600-developer-big-data-netty-netty-eventloopgroup.md].
Sources¶
^[600-developer-big-data-netty-netty-eventloopgroup.md]
Related Concepts¶
- [[Netty]]
- [[EventLoop]]
- Reactor Pattern
- [[Thread-per-EventLoop Model]]
- [[Task Scheduling]]