1

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

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

That's socket timeout, only fires when you have network problem.
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.
1
URLConnection.setConnectTimeout()
URLConnection.setReadTimeout()

@since 1.5

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.