Netty common API (II)

Before using Netty first introduced to the common API Netty's, because they have a rough idea.

A, EventLoop and EventLoopGroup

EventLoop Like its name, it is an infinite loop (Loop), in a loop continues to process the received event (Event).

Netty cornerstone threading model is based on EventLoop from the design point of view, EventLoop adopted a collaborative design, it is built on two basic API: Concurrent and Channel, and is complicated by the network. Concurrency is because it uses a thread pool to manage a large number of tasks, and these tasks can be executed concurrently. It inherited EventExecutor interface, EventExecutor is the executor of an event. Furthermore, in order to interact with the Channel events, EventLoop inherited EventLoopGroup interface. A detailed EventLoop class inheritance hierarchy is as follows:

Netty when a server is started, usually have two NioEventLoopGroup: one is listening thread group, mainly listen for client requests, and the other worker groups, mainly dealing with the client data communication.

Netty client is only one NioEventLoopGroup, is used to thread group dealing with server communication.

NioEventLoopGroup can be understood as a thread pool, to maintain a set of internal threads, each responsible for handling multiple events on the Channel, and a Channel only corresponds to a thread, so you can avoid data synchronization problems under multiple threads. NioEventLoopGroup class diagram as follows:

二、Bootstrap or ServerBootstrap

ServerBootStrap is Netty start the server configuration class, BootStrap is Netty client startup configuration class.

1. ServerBootstrap

 

2. BootStrap

 

Guess you like

Origin www.cnblogs.com/myitnews/p/11440204.html