当前位置:网站首页>The three components of NiO Foundation
The three components of NiO Foundation
2022-07-21 06:25:00 【Hua Weiyun】
One 、 Channel
channel A little similar to stream, It is the of reading and writing data Two-way channel , It can be downloaded from channel Read data into buffer, Can also be buffer Data written to channel, And before stream Or enter , Or output ,channel Than stream It's even lower .
channel There are types of , One string Of channel Only store string Type data .
Can pass Buffer As a container , Go to Channel Take out data or add data . If Channel It's a water tank , that Buffer It's the ladle that draws water .
common Channel Yes
- FileChannel
- DatagramChannel
- SocketChannel
- ServerSocketChannel
Two 、Buffer
buffer Is used to buffer read-write data , Use buffer To read or write channel The data of ,buffer Just like the array used when reading and writing files , common buffer Yes
- ByteBuffer
- MappedByteBuffer
- DirectByteBuffer
- HeapByteBuffer
- ShortBuffer
- IntBuffer
- LongBuffer
- FloatBuffer
- DoubleBuffer
- CharBuffer
3、 ... and 、 Selector
Selector Commonly referred to as selectors , It can also be translated into multiplexer , It is Java NIO One of the core components , Used to check one or more NIO Channel( passageway ) Whether the state of is readable 、 Can write
You can manage multiple threads with a single thread channels, Instead of using multiple threads , Avoid the overhead of thread context switching .
selector The function of is to cooperate with one thread to manage multiple channel, Get these channel What happened on , these channel Working in non blocking mode , It won't let the thread hang in a channel On . Suitable for a large number of connections , But low traffic scenarios (low traffic)
channel Data reading will appear in , In a single thread , Multiple channel All reads are blocked , One channel While waiting for the client to read , It's blocking other channel, If you use multithreading , It is a challenge to system performance .
and selector, It can be applied to multiple threads in a single thread channel Conduct management , adopt channel The way events are monitored , call selector Of select() Will block until channel A read-write ready event has occurred , These events happened ,select Method will return these events to thread To deal with it .
Selector Maintain registered Channel aggregate , And this registration relationship is encapsulated in SelectionKey in .selector You can customize and choose to listen to those events , The event types that can be bound are :
The bound event types can be
- connect - Triggered when the client connection is successful
- accept - Triggered when the server successfully accepts the connection
- read - Triggered when data can be read in , Yes, because the reception capacity is weak , The data cannot be read temporarily
- write - Triggered when data can be written out , Yes, because the sending ability is weak , Data cannot be written out temporarily
边栏推荐
猜你喜欢
Redis string type
Average value of sliding window of leetcode simple problem
自定义持久层框架MyORMFramework(二)—框架设计
I/O复用函数高性能框架库:libevent
全球首条“消费-投资”公链——Genesis,受邀参加Consensus 2022
Implementation of form control adaptation (adaptive form) layout in WinForm_ By C code
LeetCode简单题之环形链表
Industrial control safety PLC firmware reverse I
UE4(unreal engine4)地形编辑工具中的无法显示样条线
组件化与模块化
随机推荐
[u-boot] main line analysis of u-boot operation [03] - board_ init_ r
大数处理--使用案例
Sys_rman备份报错
自定义持久层框架MyORMFramework(二)—框架设计
配置静态路由和 RIP 路由协议
GBase 8s如何句查询关系数据库以从复杂类型中选择数据的样本语 法和结果
怎样判断你长得像哪位明星人物?
足球队巡礼 - 英超西汉姆联
I/o multiplexing function high performance framework library: libevent
递归神经网络(RNN)
基于二维声子晶体的体声波谐振器仿真分析
数字化转型迈向深水区:银行业不断夯实科技根基
工程师的基本功是什么?如何练习?—学习心得分享「建议收藏」
arthas 案例: 动态更新应用Logger Level
掌握JedisPoolConfig参数配置,学会调优技能
Mobius inversion - Summary
[u-boot] main line analysis of u-boot operation [02] - board_ init_ f
一起来自定义loader吧
全球首条“消费-投资”公链——Genesis,受邀参加Consensus 2022
《ASP.NET Core 6框架揭秘》实例演示[02]:基于路由、MVC和gRPC的应用开发