Httpclient4.0和以前3.0有很大的不同 ,分出来了HttpCore
HttpClient 两个jar包 问一下为什么现在那么麻烦 。分出来两个包。而且两个包的文档 都分开了。查api的时候
很麻烦。 官方的包里面好像没有源代码。是不是不提供源代码呀?
还有一个问题 。就是多线程去查询http的问题好像有个ThreadSafeClientConnManager类 ,可以去管理多个线程
类似如下代码 。每个线程共用了DefaultHttpClient 每个线程有个自己的 HttpGet然后去执行。。
这里与 启动多个线程 ,每次都new一个 DefaultHttpClient 有什么区别一定要用ThreadSafeClientConnManager吗?是不是性能影响很大 每次new DefaultHttpClient 。
// Create an HttpClient with the ThreadSafeClientConnManager.
// This connection manager must be used if more than one thread will
// be using the HttpClient.
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
HttpClient httpClient = new DefaultHttpClient(cm, params); // create a thread for each URI
GetThread[] threads = new GetThread[urisToGet.length];
for (int i = 0; i < threads.length; i++) {
HttpGet httpget = new HttpGet(urisToGet[i]);
threads[i] = new GetThread(httpClient, httpget, i + 1);
}
// start the threads
for (int j = 0; j < threads.length; j++) {
threads[j].start();
}
HttpClient 两个jar包 问一下为什么现在那么麻烦 。分出来两个包。而且两个包的文档 都分开了。查api的时候
很麻烦。 官方的包里面好像没有源代码。是不是不提供源代码呀?
还有一个问题 。就是多线程去查询http的问题好像有个ThreadSafeClientConnManager类 ,可以去管理多个线程
类似如下代码 。每个线程共用了DefaultHttpClient 每个线程有个自己的 HttpGet然后去执行。。
这里与 启动多个线程 ,每次都new一个 DefaultHttpClient 有什么区别一定要用ThreadSafeClientConnManager吗?是不是性能影响很大 每次new DefaultHttpClient 。
// Create an HttpClient with the ThreadSafeClientConnManager.
// This connection manager must be used if more than one thread will
// be using the HttpClient.
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
HttpClient httpClient = new DefaultHttpClient(cm, params); // create a thread for each URI
GetThread[] threads = new GetThread[urisToGet.length];
for (int i = 0; i < threads.length; i++) {
HttpGet httpget = new HttpGet(urisToGet[i]);
threads[i] = new GetThread(httpClient, httpget, i + 1);
}
// start the threads
for (int j = 0; j < threads.length; j++) {
threads[j].start();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货