I'm writing a program to check validity of URL links in Java atm. When testing the program it reguaraly gets stuck for long periods checking servers that have no response.. neither 200 nor 404, i.e., non existant servers, before timing out.
I understand there is a method called setConnectTimeout(time) that I can use that takes an int, where time is, being the timeout figure. Can't get it working tho.. mainly because I don't know what to do with it ;-)
http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLConnection.html#setConnectTimeout(int)
Any help greatly appreciated!
________________________________________________________
H:\Networks>javac SimpleURLCheck.java
SimpleURLCheck.java:92: cannot resolve symbol
symbol : method setConnectTimeout (int)
location: class SimpleURLCheck
setConnectTimeout(10);
^
1 error
--take 2:
H:\Networks>javac SimpleURLCheck.java
SimpleURLCheck.java:92: cannot resolve symbol
symbol : method setConnectTimeout (int)
location: class java.net.URLConnection
connection.setConnectTimeout(10);
^
1 error
--take 3
H:\Networks>javac SimpleURLCheck.java
SimpleURLCheck.java:92: cannot resolve symbol
symbol : method setConnectTimeout (int)
location: class java.net.URLConnection
URLConnection.setConnectTimeout(10);
^
1 error
_________________________________________________________
Bellow is a small snippet of the URLConnection part of my code..
URLConnection connection = if (connection instanceof HttpURLConnection)
{
HttpURLConnection httpConnection =
(HttpURLConnection)connection;
httpConnection.connect();
String answer = null;
int response =
httpConnection.getResponseCode();
if (response == 200)//else catch error displays
{
<snip>
}
if(response == 404)
{
}