Voglio restituire false se l'URL impiega più di 5 secondi per connettersi: come è possibile utilizzando Java? Ecco il codice che sto usando per verificare se l'URL è valido
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestMethod("HEAD");
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
java.net.ConnectException: Connection timed out: connect
prima che anche 2 minuti siano trascorsi. Sai cosa sta causando il problema?