I want to return false if the URL takes more then 5 seconds to connect - how is this possible using java? Here is the code I am using to check if the URL is valid
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestMethod("HEAD");
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);