Netty threading model (five)

Netty support single-threaded, the main thread model, master-slave multi-threading model.

When we create a thread group, if you do not pass parameters, the default thread is the thread group to build the number of cores CPU.

A single-threaded model

When ServerBootstrap calling the method group, the parameters passed to the same thread group, and when the thread group structure, structure parameter to 1, this development approach is a single-threaded model.

Personal development and testing machine use is not recommended.

ServerBootstrap bootstrap = new ServerBootstrap();
EventLoopGroup group = new NioEventLoopGroup(1);
bootstrap.group(group, group);

Second, the main thread model

When ServerBootstrap group call method, the transmission parameters are two different sets of threads. It is responsible for monitoring the thread group, the number of threads to 1, that configuration parameter to 1. Responsible for handling client tasks thread group, the number of threads is greater than 1, that structure parameter is greater than 1. This development approach is multi-threaded model.

Long connection, and the small number of client terminal connected using the longer duration. Such as: internal communication applications.

// interception request thread group 
EventLoopGroup acceptorGroup = new new NioEventLoopGroup (. 1 );
 // process the client task thread group 
EventLoopGroup clientGroup = new new NioEventLoopGroup (); 

of ServerBootstrap on Bootstrap = new new of ServerBootstrap (); 
bootstrap.group (acceptorGroup, clientGroup);

Third, the master-slave multi-threaded model

When ServerBootstrap group call method, the transmission parameters are two different sets of threads. Is responsible for monitoring the thread group, the number of threads is greater than 1, that structure parameter is greater than 1. Responsible for handling client tasks thread group, the number of threads is greater than 1, that structure parameter is greater than 1. This development approach, the Lord from multi-threading model.

Long connection, a relatively large number of clients connected to the case of using a longer duration. Such as: album server provided externally.

EventLoopGroup acceptorGroup = new NioEventLoopGroup();
EventLoopGroup clientGroup = new NioEventLoopGroup();
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(acceptorGroup, clientGroup);

 

Guess you like

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