commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: [httpclient] how to prevent slow connection from hanging up my application?
Date Fri, 29 Jul 2005 13:46:06 GMT
HttpMethod#abort() may be what you want. This method is threading safe,
so it can be safely called from an observer thread that aborts the
worker thread if it fails to terminate wintin the desired period of time

Hope this helps

Oleg


On Fri, Jul 29, 2005 at 03:38:57PM +0200, Christian Hufgard wrote:
> Hi,
> 
> to prevent our application from suffering when dealing with slow systems, we
> are using HttpClient.setTimeout() and HttpClient.setConnectionTimeout().
> Till today I tought, this would be enough.
> 
> Now, during some testing, I found out, that we have a legacy system that
> sometime tends to be really slow. We have data transfer rates below 1kB at
> documentsizes more then 60k.
> 
> Is there any way, to define an abort time? E.g. "read 20 seconds, if data is
> still missing forget about it"?.
> 
> At the moment I tend to use something like this:
> 
> 	long start = System.currentTimeMillis();
> 	int readTimeout = 20000;
> 		
> 	ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
> 	BufferedInputStream in = new BufferedInputStream(s.getInputStream());
> 	byte[] data = new byte[1024];
> 	int avail;
> 	while ((avail = in.read(data, 0, 1024)) != -1) {
> 		dataStream.write(data, 0, avail);
> 		long now = System.currentTimeMillis();
> 		if (now - start > readTimeout) {
> 			throw new IOException("Read timeout!");
> 		}
> 	}
> 
> Is there any smarter way, that I just did not find?
> 
> 
> 
> Christian
> 
> -- 
> GMX DSL = Maximale Leistung zum minimalen Preis!
> 2000 MB nur 2,99, Flatrate ab 4,99 Euro/Monat: http://www.gmx.net/de/go/dsl
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 

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


Mime
View raw message