necromancer
necromancer

Reputation: 24651

Force disconnect TCP connection when server gone

My application performs a HTTP long-poll to another server in a loop using Jersey. It relies on the server to return within 30 seconds. The problem is that sometimes the server dies and is replaced by a different one at a different IP address. This causes the last HTTP call to never return and never timeout, so the polling loop in my application is stuck until I reboot my application.

How can I force my application to either interrupt the HTTP call or to detect that the server is gone? It is a Java application using a Jersey client.

Upvotes: 0

Views: 500

Answers (1)

user207421
user207421

Reputation: 311039

Set a read timeout, with HttpURLConnection.setReadTimeout().

Upvotes: 1

Related Questions