In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what is the core part of Java NIO?". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what the core parts of Java NIO are made of.
Overview of Java NIO
Java NIO consists of the following core components:
Channels
Buffers
Selectors
Although there are many other classes and components in Java NIO, in my opinion, Channel,Buffer and Selector constitute the core API. Other components, such as Pipe and FileLock, are just utility classes used with the three core components. Therefore, I will focus on these three components in the overview. Other components are covered in a separate chapter.
Channel and Buffer
Basically, all IO starts with a Channel in NIO. Channel is a bit of a stream. Data can be read from Channel to Buffer or written from Buffer to Channel. Here is an illustration:
There are several types of Channel and Buffer. Here are some of the main Channel implementations in JAVA NIO:
FileChannel
DatagramChannel
SocketChannel
ServerSocketChannel
As you can see, these channels cover the UDP and TCP network IO, as well as the file IO.
There are some interesting interfaces with these classes, but for simplicity, I try not to mention them in the overview. I will explain what other chapters of this tutorial are related to.
Here are the key Buffer implementations in Java NIO:
ByteBuffer
CharBuffer
DoubleBuffer
FloatBuffer
IntBuffer
LongBuffer
ShortBuffer
These Buffer cover the basic data types you can send over IO: byte, short, int, long, float, double and char.
Java NIO also has a MappedByteBuffer to represent memory-mapped files, which I'm not going to describe in the overview.
Selector
Selector allows multiple Channel to be processed in a single thread. If your application opens multiple connections (channels), but the traffic to each connection is very low, it will be very convenient to use Selector. For example, in a chat server.
This is an illustration of using one Selector to process three Channel in a single thread:
To use Selector, register Channel with Selector and then call its select () method. This method blocks until some registered channel has an event ready. Once this method returns, the thread can handle these events, such as new connections, data reception, and so on.
At this point, I believe you have a deeper understanding of "what is the core part of Java NIO"? you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.