Murali
Murali

Reputation: 339

How to retry the url for n number of times in HttpUrlconnection java?

I am using HTTPUrlConnection to sending request from my server. If Connection is failure i have to retry for 3 times. Currently i am using while loop to send n number of retries.

Does any one know that any default method is there in HttpUrlconnection or else Apache Httpclient provides any default method to achieve this?

Upvotes: 1

Views: 3351

Answers (1)

Abhijith Nagarajan
Abhijith Nagarajan

Reputation: 4030

You can use connectionTimeout which makes more sense for obtaining a connection rather than retries.

http://download.java.net/jdk7/archive/b123/docs/api/java/net/URLConnection.html#setConnectTimeout(int)

To answer your question, there is no api method which takes retry attempts and act accordingly. Easy way is to use the loop as you are already doing.

Upvotes: 1

Related Questions