Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of NIO in java

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "the usage of NIO in java". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the usage of NIO in java".

Background

The IO operation in the Linux system is quite complex. Here is a LinuxIO-related hierarchy with an image:

The following is a simplified version of Linux internal IO hierarchy:

To my understanding, the java programmer version of IO understands:

IO in java

From the earliest bio's bio that only supports blocking (synchronous blocking)

Non-blocking nio is supported by default blocking (synchronous non-blocking + synchronous blocking)

Then to aio (Asynchronous non-blocking)

NIO

FileChannel: read data from a file

DatagramChannel: read and write UDP network protocol data

SocketChannel: read and write TCP network protocol data

ServerSocketChannel: can monitor TCP connections

Sample code: socket https://github.com/victorsheng/verification-everything/tree/master/io/src/main/java/socket/nio file https://github.com/victorsheng/verification-everything/tree/master/io/src/main/java/file/nio

AIO

Sample code: socket https://github.com/victorsheng/verification-everything/tree/master/io/src/main/java/socket/aio file https://github.com/victorsheng/verification-everything/tree/master/io/src/main/java/file/aio

Application of NIO

As the basic class library of jdk, it is used by many applications. Here are several common

Tomcat

Http://tomcat.apache.org/tomcat-9.0-doc/config/http.html#Connector_Comparison

Jetty

Prior to Jetty 9, the type of the connector reflected both the protocol supported (HTTP, HTTPS, AJP, SPDY), and the nature of the implementation (NIO or BIO). From Jetty 9 onwards there is only one prime Connector type (ServerConnector), which is NIO based and uses Connection Factories to handle one or more protocols.

Https://www.eclipse.org/jetty/documentation/9.4.x/quickstart-config-what.html#intro-jetty-configuration-connectors

Netty

As the most commonly used encapsulation class library for nio

Summary

Nio is more concerned with the waste of thread resources than the improvement of response time for individual operations.

Use NIO! = high performance, when the number of connections

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report