tags:

views:

112

answers:

1

Hi All

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.

+3  A: 

You can also set socket read timeou using setSoTimeout() but that is no guarantee either.

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. See my answer to this question for examples,

http://stackoverflow.com/questions/1247390/java-native-process-timeout/1249984#1249984

ZZ Coder
Yea , seems I'll have to execute it in another thread..
Roman