没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
http://gee.cs.oswego.edu
Scalable IO in Java
Doug Lea
State University of New York at Oswego
dl@cs.oswego.edu
http://gee.cs.oswego.edu
http://gee.cs.oswego.edu
Outline
"
Scalable network services
"
Event-driven processing
"
Reactor pattern
Basic version
Multithreaded versions
Other variants
"
Walkthrough of java.nio nonblocking IO APIs
http://gee.cs.oswego.edu
Network Services
"
Web services, Distributed Objects, etc
"
Most have same basic structure:
Read request
Decode request
Process service
Encode reply
Send reply
"
But differ in nature and cost of each step
XML parsing, File transfer, Web page
generation, computational services, ...
http://gee.cs.oswego.edu
Classic Service Designs
client
client
client
Server
read
decode
compute
encode
send
read
decode
compute
encode
send
handler
handler
read
decode
compute
encode
send
handler
Each handler may be started in its own thread
http://gee.cs.oswego.edu
Classic ServerSocket Loop
class Server implements Runnable {
public void run() {
try {
ServerSocket ss = new ServerSocket(PORT);
while (!Thread.interrupted())
new Thread(new Handler(ss.accept())).start();
// or, single-threaded, or a thread pool
} catch (IOException ex) { /* ... */ }
}
static class Handler implements Runnable {
final Socket socket;
Handler(Socket s) { socket = s; }
public void run() {
try {
byte[] input = new byte[MAX_INPUT];
socket.getInputStream().read(input);
byte[] output = process(input);
socket.getOutputStream().write(output);
} catch (IOException ex) { /* ... */ }
}
private byte[] process(byte[] cmd) { /* ... */ }
}
}
Note: most exception handling elided from code examples
剩余38页未读,继续阅读
资源评论
- 程序员一护2019-01-03太好了不愧是大神
- 木匠之子2018-06-10资源很好,但是太贵。这个资源可以从官方网站免费下载到: http://gee.cs.oswego.edu/dl/cpjslides/nio.pdf
高效能人生
- 粉丝: 32
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- AIS2024 valid
- 最入门的爬虫代码 python.docx
- 爬虫零基础入门-爬取天气预报.pdf
- 最通俗易懂的 MongoDB 非结构化文档存储数据库教程.zip
- 以mongodb为数据库的订单物流小项目.zip
- 腾讯云-mongodb数据库, 项目部署.zip
- 腾讯 APIJSON 的 MongoDB 数据库插件.zip
- 理解非关系型数据库和关系型数据库的区别.zip
- 操作简单的Mongodb网页web管理工具,基于Spring Boot2.0支持mongodb集群.zip
- tms-mongodb-web,提供访问mongodb数据的REST API和可灵活扩展的mongodb web 客户端.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功