简体   繁体   English

org.apache.commons.httpclient.HttpClient卡在请求上

[英]org.apache.commons.httpclient.HttpClient stuck on request

I have that code : 我有该代码:

 while(!lastPage && currentPage < maxPageSize){


            StringBuilder request = new StringBuilder("http://catalog.bizrate.com/services/catalog/v1/us/" + " some more ...");

            currentPage++;
            HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager());
            client.getHttpConnectionManager().getParams().setConnectionTimeout(15000);



            GetMethod get = new GetMethod(request.toString());

            HostConfiguration configuration = new HostConfiguration();

            int iGetResultCode = client.executeMethod(configuration, get);
            if (iGetResultCode != HttpStatus.SC_OK) {
                System.err.println("Method failed: " + get.getStatusLine());
                return;
            }
            XMLStreamReader reader
                    = XMLInputFactory.newInstance().createXMLStreamReader(get.getResponseBodyAsStream());
            while (reader.hasNext()) {
                int type = reader.next();
            // some more xml parsing ... 
            }
            reader.close();
            get.releaseConnection();
          }

Somehow the code gets suck from time to time on line : executing request. 不知何故,代码不时在线上:执行请求。

I cant find the configuration for a request time out (not the connection timeout) , can someone help me maybe , or is there something that I am doing basely wrong ? 我找不到请求超时(而不是连接超时)的配置,也许有人可以帮助我,还是我在做一些根本错误的事情?

The client I am using. 我正在使用的客户端

You can also set socket read timeou using setSoTimeout() but that is no guarantee either. 您也可以使用setSoTimeout()设置套接字读取timeou,但这也不保证。

The only solution is to run the request in a different thread and interrupt the thread after timeout. 唯一的解决方案是在另一个线程中运行请求,并在超时后中断该线程。 You can use FutureTask to do this. 您可以使用FutureTask来执行此操作。 See my answer to this question for examples, 有关示例,请参见我对这个问题的回答,

java native Process timeout java本机进程超时

PoolingConnectionManager maintains a maximum limit of connection on a per route basis and in total. PoolingConnectionManager维护每个路由的总连接数上限。 Per default this implementation will create no more than than 2 concurrent connections per given route and no more 20 connections in total. 默认情况下,此实现将为每个给定路由创建不超过2个并发连接,并且总共不超过20个连接。 For many real-world applications these limits may prove too constraining, especially if they use HTTP as a transport protocol for their services. 对于许多现实应用程序,这些限制可能证明过于严格,特别是如果它们使用HTTP作为其服务的传输协议。 Connection limits, however, can be adjusted using HTTP parameters. 但是,可以使用HTTP参数来调整连接限制。 For more information, you can refer to PoolingClientConnectionManager Java API 有关更多信息,您可以参考PoolingClientConnectionManager Java API。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用org.apache.commons.httpclient.HttpClient将数据流发送到多个URL - Sending data stream to multiple URLs using org.apache.commons.httpclient.HttpClient 导入org.apache.commons.httpclient。* - import org.apache.commons.httpclient.* java.lang.NoClassDefFoundError: org/apache/commons/httpclient/Credentials 错误 - java.lang.NoClassDefFoundError: org/apache/commons/httpclient/Credentials error 软件包org.apache.commons.httpclient不存在导入org.apache.commons.httpclient。*; 编译Java时 - package org.apache.commons.httpclient does not exist import org.apache.commons.httpclient.*; While compiling Java 用于HTTPS调用的Apache Commons HttpClient - Apache Commons HttpClient for HTTPS call http客户端中发生意外错误。 org.apache.commons.httpclient.ProtocolException:不能重复未缓冲的实体封装请求 - Unexpected error occurred in http client. org.apache.commons.httpclient.ProtocolException: Unbuffered entity enclosing request can not be repeated Apache Commons HttpClient PostMethod 支持? - Apache Commons HttpClient PostMethod support? 如何将安全性Cookie传递到HttpClient Get请求(Apache Commons) - How to pass security cookies into a HttpClient Get request (Apache Commons) org.apache.http.client.methods.HttpPost和org.apache.commons.httpclient.methods.PostMethod之间的区别? - Difference between org.apache.http.client.methods.HttpPost and org.apache.commons.httpclient.methods.PostMethod? Apache HttpClient SOAP 请求 - Apache HttpClient SOAP Request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM