commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Hufgard" <>
Subject [httpclient] how to prevent slow connection from hanging up my application?
Date Fri, 29 Jul 2005 13:38:57 GMT

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 =, 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?


GMX DSL = Maximale Leistung zum minimalen Preis!
2000 MB nur 2,99, Flatrate ab 4,99 Euro/Monat:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message