hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "KOTA, KUMAR \(SBCSI\)" <kk9...@sbc.com>
Subject Inconsistent socket time outs
Date Tue, 15 Mar 2005 21:56:35 GMT
Hi All,

    I am trying to timeout the socket using the httpclient setSoTimeout
but I am receiving inconsistent results.  The code I use is displayed
below.  What is happenening is, sometimes the client.executeMethod is
timing out and going straight to AREA 3 (indicated below).  But
sometimes, the client.executeMethod is not timing out, it goes to AREA 2
and then the bufferedReader.readLine() is timing out and it goes to AREA
3.  This behavior happens randomly (about 35% of the time) and
frequently enough to cause problems.  Any help on this would be great.

For example:  if timeout value is set to 7 seconds, client.executeMethod
runs for 4 seconds, passes to AREA 2 and then bufferedReader.readLine()
reads for 7 seconds and then times out (goes to AREA 3).  Whereas in
other cases, client.executeMethod directly times out at 7 secnods and
goes straight to AREA 3.



Here is the code:

try{
     //MultiThreadedConnectionManager
     MultiThreadedHttpConnectionManager manager = new
MultiThreadedHttpConnectionManager();
     HttpConnectionManagerParams params = manager.getParams();
     params.setSoTimeout(timeoutVal);
     manager.setParams(params);

	// Create an instance of HttpClient.
    	HttpClient client = new HttpClient(manager);

	/************AREA 1******************************************/
		
      // Execute the method.
      int statusCode = client.executeMethod(method);
	
	InputStream response = method.getResponseBodyAsStream();

	inpstrmrdr = new InputStreamReader(response);
	bufferedReader = new BufferedReader(inpstrmrdr);
	String outputline = "";	

	/********* AREA 2 *******************************************/
	
	while ((outputline = bufferedReader.readLine()) != null) {

		if (outputline.length() != 0) {
			sResponse = sResponse + outputline + "\n";
			//System.out.println("***********sResponse***" +
sResponse);
		}
	}

} catch (java.io.InterruptedIOException e) {
    
     /********** AREA 3*********************************************/

}

Thank you,
Kumar Kota

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org


Mime
View raw message