tags: High-performance programming java netty Multithreading
Netty is a high-performance, highly scalable asynchronous event-driven network application framework, which greatly simplifies network programming such as TCP and UDP client and server development.
Four important aspects of Netty:

/**
* Echoes back any received data from a client.
*/
public final class EchoServer {
static final int PORT = Integer.parseInt(System.getProperty("port", "8080"));
public static void main(String[] args) throws Exception {
// Configure the server.
// Create EventLoopGroup accept thread group NioEventLoop
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
// Create EventLoopGroup I/O thread group
EventLoopGroup workerGroup2 = new NioEventLoopGroup(1);
try {
// The server starts the boot tool class
ServerBootstrap b = new ServerBootstrap();
// Configure the reactor thread group processed by the server and other configurations of the server
b.group(bossGroup, workerGroup2).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100)
.handler(new LoggingHandler(LogLevel.DEBUG)).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new com.study.hc.net.netty.EchoServerHandler());
}
});
// Start the service through bind
ChannelFuture f = b.bind(PORT).sync();
// Block the main thread, knowing that the network service is closed
f.channel().closeFuture().sync();
} finally {
// Close the thread group
bossGroup.shutdownGracefully();
workerGroup2.shutdownGracefully();
}
}
}
In order to make NIO processing better use of multi-threading features, Netty implements the Reactor threading model.
There are four core concepts in the Reactor model:


EventLoop itself implements the Executor interface. When the executor method is called to submit a task, it is judged whether to start, and if it is started, the built-in executor is called to trigger the execution of the run method.


Channel in netty is an abstract concept, which can be understood as an enhancement and expansion of JDK NIO Channel. Many properties and methods have been added. For complete information, please refer to the code comments. Here are a few common properties and methods:

Zero copy hard driver - kernel buffer - protocol engine only DMA copy avoids cpu copy There was actually a cpu copy of kernel buffer - socket buffer, but the copied information can rarely be ignored; ...
Introduction to Netty Netty is a high-performance, high-scalable asynchronous event-driven network application framework, which greatly simplifies network programming such as TCP and UDP clients and s...
Why use Netty Netty is an asynchronous event-driven web application framework for rapid development of maintainable high-performance and high-profile servers and clients. Netty has the advantages of h...
Event cycle group All I / O operations in Netty are asynchronous, and the asynchronous execution results are obtained by channelfuture. Asynchronously executes a thread pool EventLoopGroup, it ...
table of Contents Thread model 1, traditional IO service model 2, Reactor mode reactor Three modes: to sum up Netty model Excommissum Thread model 1, traditional IO service model Blocked IO mode Get i...
Hey everyone, I amJava small white 2021。 The programmer of the halfway is in the development of aircraft, and the opportunity to find a more interesting thing under the development of a surveying cour...
content 1. Single Reactor single thread 2. Single Reactor Multi -thread 3. Reactor Main Strike Model Single -threaded model (single Reactor single thread) Multi -threaded model (single Reactor multi -...
Single-threaded model: the boss thread is responsible for connection and data reading and writing Hybrid model: the boss thread is responsible for connection and data reading and writing, and the work...
This chapter of the Redis database server implementations are introduced, indicating achieve Redis database-related operations, including key-value pairs in the database to add, delete, view, update a...
1、b1041 2、b1042 3、b1043 4、b1044 5、b1045...