mabuzer
mabuzer

Reputation: 6717

Connection timeout in java?

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

Upvotes: 1

Views: 1820

Answers (2)

user207421
user207421

Reputation: 311050

URLConnection.setConnectTimeout()
URLConnection.setReadTimeout()

@since 1.5

Upvotes: 1

ZZ Coder
ZZ Coder

Reputation: 75496

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

Upvotes: 2

Related Questions