Executor Interface Implementations¶
The Executor interface serves as a foundational abstraction in Java for decoupling task submission from task execution mechanics.^[600-developer__big-data__netty__netty-EventLoopGroup.md] It is designed to invoke java.util.concurrent.Executor, functioning as a Functional Interface that accepts a Runnable command.^[600-developer__big-data__netty__netty-EventLoopGroup.md]
Standard Usage¶
In typical scenarios, an Executor is obtained through the Executors utility class using factory methods such as newFixedThreadPool or newCachedThreadPool.^[600-developer__big-data__netty__netty-EventLoopGroup.md] Once an instance is retrieved, tasks (usually Runnable objects) are passed to the execute method to be processed by the underlying execution logic.^[600-developer__big-data__netty__netty-EventLoopGroup.md]
Common Implementations¶
The behavior of an Executor depends entirely on its implementation.^[600-developer__big-data__netty__netty-EventLoopGroup.md] Common custom implementations include:
- DirectExecutor: Executes tasks synchronously in the caller's thread by calling
Runnable.run()directly.^[600-developer__big-data__netty__netty-EventLoopGroup.md] - ThreadPerTaskExecutor: Spawns a new thread for every task submitted via
new Thread(r).start().^[600-developer__big-data__netty__netty-EventLoopGroup.md] - SerialExecutor: A composite executor that maintains a queue (e.g.,
ArrayDeque) to ensure that submitted tasks are executed sequentially.^[600-developer__big-data__netty__netty-EventLoopGroup.md] This implementation synchronizes access to the task queue to ensure only one task is active at a time, using a secondary executor to perform the actual work.^[600-developer__big-data__netty__netty-EventLoopGroup.md]
Netty Hierarchy¶
Within the Netty framework, the Executor concept is extended to support asynchronous event-driven architectures.^[600-developer__big-data__netty__netty-EventLoopGroup.md]
- EventExecutor: Acts as a base for specialized executors.^[600-developer__big-data__netty__netty-EventLoopGroup.md]
- SingleThreadEventExecutor: An abstract implementation that handles task execution on a single thread.^[600-developer__big-data__netty__netty-EventLoopGroup.md]
- SingleThreadEventLoop: Extends the single-thread executor to add features specific to I/O event loops.^[600-developer__big-data__netty__netty-EventLoopGroup.md]
- NioEventLoopGroup: A specific implementation of
EventLoopGroupthat manages a collection ofNioEventLoopinstances (which themselves extendSingleThreadEventLoop).^[600-developer__big-data__netty__netty-EventLoopGroup.md]
Related Concepts¶
- [[EventLoopGroup]]
- [[Reactive Programming]]
- [[Concurrency Control]]
Sources¶
^[600-developer__big-data__netty__netty-EventLoopGroup.md]