- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
解读nio socket非阻塞模式(解读nio socket非阻塞模式)
解读nio socket非阻塞模式(解读nio socket非阻塞模式)
Preface:
The non blocking I/O (NIO) provided by JDK effectively solves the thread overhead problem of multithreaded servers, but it seems a little more complicated in use.
In NIO, the main purpose of using multithreading is not to allocate separate service threads to each client request,
But through the use of multi-threaded, with multiple CPU processing capacity and processing latency, to improve service capabilities.
Its time to study NIO and write a blog to remember what you learned. Or start with the simplest Hello World,
Client multithreaded request server side, server receive the name of client, and return Hello + name character format to client.
Of course, the actual application is not so simple. It might actually be accessing files or databases and getting information back to client. Whats the mystery about non blocking NIO? Code:
1) server side code
Java code
/ * *
*
* @author Jeff
*
* /
Public, class, HelloWorldServer {
Static int BLOCK = 1024;
Static, String, name =;
Protected Selector selector;
Protected, ByteBuffer, clientBuffer = ByteBuffer.allocate (BLOCK);
Protected CharsetDecoder decoder;
Static, CharsetEncoder, encoder = Charset.forName (GB2312),.NewEncoder ();
Public HelloWorldServer (int port) throws IOException {
Selector = this.getSelector (port);
Charset charset = Charset.forName (GB2312);
Decoder = charset.newDecoder ();
}
Get / / Selector
Protected, Selector, getSelector (int, port), throws, IOException {
ServerSocketChannel server = ServerSocketChannel.open ();
Selector sel = Selector.open ();
Server.socket ().Bind (new, InetSocketAddress (port));
Server.configureBlocking (false);
Server.register (SEL, SelectionKey.OP_ACCEPT);
Return sel;
}
/ / listen port
Public, void, listen () {
{try
For ((=)) {
Selector.select ();
Iterator ITER = selector.selectedKeys ().Iterator ();
While (iter.hasNext ()) {
SelectionKey key = (SelectionKey) iter.next ();
Iter.remove ();
Process (key);
}
}
} catch (IOException, e) {
您可能关注的文档
- 七年级下册语文题第二单元(Grade seven Chinese second unit).doc
- 七年级语文上册 第1课《为你打开一扇门》同步练习 苏教版(Grade seven Chinese census first class open a door for you synchronous exercises Jiangsu).doc
- 七年级语文上册 第三单元同步练习 语文版(Grade seven Chinese census of third synchronized exercises Chinese version).doc
- 七年级语文上册 第六单元检测卷(一) 人教新课标版(Grade seven Chinese census unit sixth detection volume (a) taught the new curriculum version).doc
- 万古汇力以先锋姿态企业培训专注ehr(The power to pioneer attitude training focus on EHR).doc
- 万斯同《明史稿》(Wan Sitong Ming history).doc
- 万用表检测元器件(Multimeter to detect components).doc
- 七年级语文上册《帮你学作文》第六单元试题(无答案)人教新课标版(Grade seven Chinese census to help you learn the composition sixth unit test (no answer) taught the new curriculum version).doc
- 万峰经典语录升级版(Wan Feng classic quotations upgraded version).doc
- 万科企业股份有限公司(Vanke enterprise Limited by Share Ltd).doc
- 解读t-50俄罗斯磕磕碰碰撞出一条路(T-50 interpretation Russia kekepengpeng hit a path).doc
- 解决绩效低落的难题(Solve the problem of low performance).doc
- 解读九章算术之方田(Interpretation of the nine chapter, arithmetic of Tian Tian).doc
- 解读储蓄实名制(Interpretation of savings real name system).doc
- 解读考研英语中的虚拟语气(Interpretation of subjunctive mood in English for postgraduate studies).doc
- 解读高考平行志愿(Interpretation of parallel voluntary in college entrance examination).doc
- 解读齐物论11(Interpretation of the theory of the unity of things 11).doc
- 解读齐物论5(Interpretation of the theory of the unity of things 5).doc
- 解读独生子女费发放的企业培训四大误区(Interpretation of the four major misunderstandings of enterprise training for the only child payment).doc
- 解读齐物论8(Interpretation of the theory of the unity of things 8).doc
最近下载
- 智慧城市云计算大数据中心项目深化设计方案(403页word).docx VIP
- 全国高中青年数学教师优质课大赛一等奖《基本不等式》教学设计.doc VIP
- 中华民族共同体概论第一讲 中华民族共同体基础理论part1.pptx VIP
- 儿童绘本改编与创作教案.pdf VIP
- JGJ-T291-2012:现浇塑性混凝土防渗芯墙施工技术规程.pdf VIP
- 实施指南《GB_T18944.2-2022柔性多孔聚合物材料海绵和发泡橡胶制品规范第2部分:模制品与挤出制品》实施指南.docx VIP
- 2022新能源风电场接入集控中心技术方案.doc VIP
- 白头翁的故事培智.ppt VIP
- 应聘人员登记表单.docx VIP
- 5S_培训教材.ppt VIP
文档评论(0)