httpclient单线程get论坛的url,大约一千多个url……进行到中途会发生假死的情况,即卡住了,也不报错……主要代码如下,没有设置超时,不过好像设置了也发生过假死的情况 MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
HttpClient httpClient = new HttpClient(connectionManager);
GetMethod getMethod = new GetMethod(url);
getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler()); try {
httpClient.executeMethod(getMethod);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} InputStream is = null;
try {
is = getMethod.getResponseBodyAsStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
StringBuffer buf = new StringBuffer();
byte b[] = new byte[16384];
int len = 0;
try {
while ((len = is.read(b)) > 0) {
buf.append(new String(b, 0, len, "gb2312"));
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.flush();//强制刷新
HttpClient httpClient = new HttpClient(connectionManager);
GetMethod getMethod = new GetMethod(url);
getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler()); try {
httpClient.executeMethod(getMethod);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} InputStream is = null;
try {
is = getMethod.getResponseBodyAsStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
StringBuffer buf = new StringBuffer();
byte b[] = new byte[16384];
int len = 0;
try {
while ((len = is.read(b)) > 0) {
buf.append(new String(b, 0, len, "gb2312"));
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.flush();//强制刷新
解决方案 »
- 为什么我的js没有运行
- JS导出EXCEL的设置问题,求高手指点????
- 关于Json问题,希望能把这100分送出去
- 大家看看我的JSP程序错在哪里
- 请问如何使用JSP实现页面缓存
- 怎样使用ResultSet对象可以得到一个结果集的记录数(就象在asp中RecordSet的RecordCount属性一样)?
- 新手的问题--当一个用户访问一个页面,或者说是进行一次搜索,当第一次访问的时候,生成静态页面,在第二次,或者以后访问,就直接访问这
- 一个显示数据库中数据的简单问题
- flex中大数字从XML中取出转换成ArrayCollection时纯数字字符转换成数字
- 动态关联下拉列表,要求列表值从数据库中提取!
- struts2+spring+hibernate都用什么jar包,不是用myeclipse导入的那些。手动加都需要什么包?
- 请教个调存储过程的问题
网上查了下httpclient有两种超时 一种是 http连接超时,一种是get请求超时,对这两种超时不是很了解
难道用httpclient的人很少?