Here you can find the source of checkUrl(String url, int timeout)
public static int checkUrl(String url, int timeout)
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static int checkUrl(String url, int timeout) { try {// ww w . ja va 2s. c o m URL url2 = null; HttpURLConnection conn = null; url2 = new URL(url); conn = (HttpURLConnection) url2.openConnection(); long len = conn.getContentLength(); conn.setConnectTimeout(timeout); return conn.getResponseCode(); } catch (IOException e) { e.printStackTrace(); return -1; } } public static int checkUrl(String url) { return checkUrl(url, 2000); } }