B
billdavidcn
I find a very confusing problem during testing my application:
I will send some notification message to a URL provided by user in my
web service. If user has provided a right URL (with an IP in using and
a right port and context), everything goes well. But if user has
provided an IP that is not reachable, the waiting time may be very long
(40 ~ 300 seconds). Especially when the IP is of the same subnet but
not in use, the waiting time may be more than 5 minutes.
To shorten the waiting time, I have added the following code to check
if the URL is accessible before sending notification:
int REQUEST_TIMEOUT = 15000; // 15 seconds
// Check if url is accessible or not
URL url = new URL(endPoint);
HttpURLConnection connection = (HttpURLConnection)
url.openConnection();
connection.setConnectTimeout(REQUEST_TIMEOUT);
connection.setReadTimeout(REQUEST_TIMEOUT);
connection.connect();
connection.disconnect();
But the result is not very good, we still need wait 40~70 seconds to
get the socket connection failed exception.
Is there any method to check if a URL is accessible in a shorter time?
I will send some notification message to a URL provided by user in my
web service. If user has provided a right URL (with an IP in using and
a right port and context), everything goes well. But if user has
provided an IP that is not reachable, the waiting time may be very long
(40 ~ 300 seconds). Especially when the IP is of the same subnet but
not in use, the waiting time may be more than 5 minutes.
To shorten the waiting time, I have added the following code to check
if the URL is accessible before sending notification:
int REQUEST_TIMEOUT = 15000; // 15 seconds
// Check if url is accessible or not
URL url = new URL(endPoint);
HttpURLConnection connection = (HttpURLConnection)
url.openConnection();
connection.setConnectTimeout(REQUEST_TIMEOUT);
connection.setReadTimeout(REQUEST_TIMEOUT);
connection.connect();
connection.disconnect();
But the result is not very good, we still need wait 40~70 seconds to
get the socket connection failed exception.
Is there any method to check if a URL is accessible in a shorter time?