1

Is there any way to fire an event if HttpURLConnection has timeout before complete?

Jonik
  • 80,077
  • 70
  • 264
  • 372
mabuzer
  • 6,497
  • 6
  • 35
  • 41

2 Answers2

2

There is no built-in timeout for this. What I do is to use a different thread and interrupt the thread after the timeout.

It's easier to use FutureTask for this. See my answer to this question,

java native Process timeout

Community
  • 1
  • 1
ZZ Coder
  • 74,484
  • 29
  • 137
  • 169
  • That's socket timeout, only fires when you have network problem. – ZZ Coder May 31 '10 at 14:18
  • completely incorrect. Connection timeout fires when you can't connect within the timeout, and read timeout fires if there is nothing to read within the timeout for any reason, including the server not sending anything. – user207421 May 16 '11 at 02:39
1
URLConnection.setConnectTimeout()
URLConnection.setReadTimeout()

@since 1.5

user207421
  • 305,947
  • 44
  • 307
  • 483