0

There are many similar questions and

HttpURLConnection con = (HttpURLConnection) new URL("www.google.com").openConnection();

con.setReadTimeout(1000);

Is not a solution. I need to limit available time for download where if it takes more than 3 seconds to download the file it would throw an exception. setReadTimeout is respected only if data is not available for read for specified time which is totally different.

I'd like to prevent unpredictable thread block periods when reading from slow content providers.

Aubergine
  • 5,862
  • 19
  • 66
  • 110
  • No download is going on in the code shown in the question. There is nothing to limit. – Andreas Aug 22 '18 at 17:48
  • Check out this answer: https://stackoverflow.com/questions/804951/is-it-possible-to-read-from-a-inputstream-with-a-timeout – Kostiantyn Aug 22 '18 at 17:58
  • @Andreas reaaally :-) ? OK, I am using DataHandler accepting URL for SOAP but principle is the same as in : https://www.codejava.net/java-se/networking/use-httpurlconnection-to-download-file-from-an-http-url – Aubergine Aug 22 '18 at 19:42
  • @Aubergine Ahh, but see, in *that* code the actual downloading is happening in the `while` loop, and you can easily add an `if` statement inside the loop to break out if elapsed time has exceeded a limit. Without code in your question that does an *actual* download, how can we suggest enhancement to the code to accomplish your desired goal? – Andreas Aug 22 '18 at 20:36
  • @Andreas I will add more details ta. – Aubergine Aug 23 '18 at 08:41

0 Answers0