博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Async Java HTTP client
阅读量:6411 次
发布时间:2019-06-23

本文共 1369 字,大约阅读时间需要 4 分钟。

I spent some of my spare time writing , an intelligent RSS reader, I want it to be smart enough to highlight stories I like, and help me discover stories I may like.

I plan to do it by downloading as many web pages as possible from the Internet, extract RSS links it contains, download them, then apply machine learning algorithms on them. It’s ambitious.

The first thing need to be solved is an Http client. JDK’s is blocking, 20 threads devoted to it, still not fast enough, and there are some keepalive timer come out of the way. The non-blocking is tried, it works great, but it lacks socks proxy support, and I want to control everything.

So, I write my own async HTTP client, by using a great library , which provides a async socket framework and HTTP codec.

// Http client sample usage   HttpClientConfig config = new HttpClientConfig();   header = new HashMap
(); HttpClient client = new HttpClient(config); URI uri = new URI("http://onycloud.com"); final HttpResponseFuture future = client.execGet(uri, header); resp.addListener(new Runnable() {
public void run() {
HttpResponse resp = future.get(); // async } }); HttpResponse resp = future.get(); // blocking

The source code is concise, about 1000 lines of code(about 600 lines excluding import statements and blank lines), can be found on .

转载地址:http://swzra.baihongyu.com/

你可能感兴趣的文章
Tensorflow Serving 模型部署和服务
查看>>
Java Web开发详解——XML+DTD+XML Schema+XSLT+Servlet 3.0+JSP 2.2深入剖析与实例应用
查看>>
topcoder srm 680 div1 -3
查看>>
具体数学第二版第四章习题(1)
查看>>
高效前端优化工具--Fiddler入门教程
查看>>
【翻译】我钟爱的HTML5和CSS3在线工具
查看>>
Java多线程学习(吐血超详细总结)
查看>>
css3 变形
查看>>
Win7 64bit 安装Mysql5 出错 无法启动服务。
查看>>
嵌入式 H264参数语法文档: SPS、PPS、IDR以及NALU编码规律
查看>>
初识Opserver,StackExchange的监控解决方案
查看>>
给大家讲解一下JavaScript与后台Java天衣无缝相结合
查看>>
探索HTML5之本地文件系统API - File System API
查看>>
javascript有用代码块(1)
查看>>
libevent 笔记
查看>>
PHP实现人人OAuth登录和API调用
查看>>
redis源码笔记 - initServer
查看>>
FindBugs工具常见问题
查看>>
ECSHOP报错误Deprecated: preg_replace(): The /e modifier is depr
查看>>
【iOS】iOS之Button segue弹出popOver消除(dismiss)问题
查看>>