基于netty开发的支持并发的http客户端。。。 后台将会维护一个tcp的长连接池。。。。
用法就看 我的博客吧: http://blog.csdn.net/fjslovejhl/article/details/33340755
基于netty实现的支持并发的http客户端
基于netty开发的支持并发的http客户端。。。 后台将会维护一个tcp的长连接池。。。。
用法就看 我的博客吧: http://blog.csdn.net/fjslovejhl/article/details/33340755
测试代码如下:
public static void main(String args[]) throws Throwable {
final ClientPool pool = new NettyClientPool(1, "127.0.0.1");
pool.start();
for (int i = 0; i < 5; i++) {
new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 1000; i++) {
String name = Thread.currentThread().getName();
Request request = new Request("/", Request.RequestMethod.POST);
request.getBody().writeBytes((name+" "+i + "aa").getBytes(Charset.forName("utf-8")));
Response response = null;
try {
response = pool.requestWithTimeOut(request, 30000).sync();
//pool.stop();
System.out.println(response.getBody().toString(Charset.forName("utf-8")));
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
}).start();
}
}
在ChannelRead方法中会概率性抛出:client.getRequest()空指针异常,一直没搞明白为什么会抛出这个异常,猜测是client.ready()使用了setRequest(null),但是我看这个方法是同步的 按道理不应该
if (msg instanceof LastHttpContent) {
Response nr = new Response(this.response, this.body);
this.body = null;
if ( client.getRequest()
.getFuture()
.getStatus()
.equals(Future.FutureStatus.Running)) {
client.getRequest().getFuture().success(nr);
} else {
Logger.getLogger("main").warning("请求执行付完毕,但是请求状态不对:"+nr.getBody().toString(Charset.defaultCharset()));
}
client.ready();
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.