httpclient的疑问求解答
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了httpclient的疑问求解答相关的知识,希望对你有一定的参考价值。
参考技术A 你多线程是用httpclient用错了,如果你需要多线程使用httpclient的话,请看这个例子
Java代码
public class ClientMultiThreadedExecution
public static void main(String[] args) throws Exception
// Create and initialize HTTP parameters
HttpParams params = new BasicHttpParams();
ConnManagerParams.setMaxTotalConnections(params, 100);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
// Create and initialize scheme registry
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(
new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
// 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 an array of URIs to perform GETs on
String[] urisToGet =
"http://hc.apache.org/",
"http://hc.apache.org/httpcomponents-core/",
"http://hc.apache.org/httpcomponents-client/",
"http://svn.apache.org/viewvc/httpcomponents/"
;
// 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();
// join the threads
for (int j = 0; j < threads.length; j++)
threads[j].join();
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpClient.getConnectionManager().shutdown();
/**
* A thread that performs a GET.
*/
static class GetThread extends Thread
private final HttpClient httpClient;
private final HttpContext context;
private final HttpGet httpget;
private final int id;
public GetThread(HttpClient httpClient, HttpGet httpget, int id)
this.httpClient = httpClient;
this.context = new BasicHttpContext();
this.httpget = httpget;
this.id = id;
/**
* Executes the GetMethod and prints some status information.
*/
@Override
public void run()
System.out.println(id + " - about to get something from " + httpget.getURI());
try
// execute the method
HttpResponse response = httpClient.execute(httpget, context);
System.out.println(id + " - get executed");
// get the response body as an array of bytes
HttpEntity entity = response.getEntity();
if (entity != null)
byte[] bytes = EntityUtils.toByteArray(entity);
System.out.println(id + " - " + bytes.length + " bytes read");
catch (Exception e)
httpget.abort();
System.out.println(id + " - error: " + e);
本回答被提问者和网友采纳
求dalao解答弱的疑问
1.
#include <stdio.h>
#define maxsize 32575
typedef int SElemType;
typedef struct stack{
SElemType *base,*top;
int stacksize;
}stack;
int Initstack(stack S){
S.base = new stack[maxsize];
if(!S.base)
return -1;
S.base = S.top;
S.stacksize = maxsize;
return 0;
}
int push(stack S,SElemType e){
if(S.top -S.base == S.stacksize)
return -1;
*(S.top++) = e;
return e;
}
int pop(stack S,SElemType e){
if(S.top == S.base)
return -1;
e = *--S.top;
return 1;
}
int stackEmpty(stack S){
if(S.base == S.top)
return -1;
return 0;
}
//十进制转换为八进制
int main(int a){
Initstack(S);
stackEmpty(S);
while(a){
push(S,a%8);
a = a/8;
}
while(!stackEmpty(S)){
pop(S,e);
printf("%d",e);
}
delete S;
return 0;
}
--------------------Configuration: hello - Win32 Debug--------------------
Compiling...
hello.cpp
D:\\vc2016.10.23\\MyProjects\\first2\\hello.cpp(10) : error C2440: ‘=‘ : cannot convert from ‘struct stack *‘ to ‘int *‘
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\\vc2016.10.23\\MyProjects\\first2\\hello.cpp(39) : error C2065: ‘S‘ : undeclared identifier
D:\\vc2016.10.23\\MyProjects\\first2\\hello.cpp(46) : fatal error C1903: unable to recover from previous error(s); stopping compilation
执行 cl.exe 时出错.
hello.obj - 1 error(s), 0 warning(s)
2.区别理解
p= NULL
P-> next =NULL
3.邻接表 后面的链表为什么不用数组 减少循环
4.、、注意边界、特殊情况、、抽象实际图 --》 本质关系图
5.
区别
SqQueue &Q
SqQueue *Q
SqQueue Q
6.
什么时候使用
-》
。
多看些例子也许会明白,特别是连个连起来都要使用的情况
7.
前、后插法建单链表为什么要带头结点
构造一个空栈,栈顶置空,是不是和不带头结点一个意思?
8.
++i i++ --i i--
是由很大的区别 即使是在循环条件中也是非常重要的
注意n》 = 0 应该有否等于号 边界问题很重要
这里循环从0开始, ++i 就没有了0,直接从下标1开始
//十进制转任意进制
#include <stdio.h>
int main(){
int i,n,r,a[2000];
while(scanf("%d,%d",&n,&r)!= EOF){
i =0;
if(n<0){
printf("-");
n = -n;
}
while(n>0){
a[i++] = n%r;
n /= r;
}
for(i -=1;i>=0;--i){
printf("%X",a[i]);
printf("\\n");
}
}
return 0;
}
以上是关于httpclient的疑问求解答的主要内容,如果未能解决你的问题,请参考以下文章
win10之前执行过的,换台电脑,一执行就闪退,求大神解答一下疑问