// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.*;
import java.net.*;

public class Timeout {
    public static int test(String url) {
        long t1 = System.currentTimeMillis();
        try {
            URL url2 = new URL(url);
            HttpURLConnection con = (HttpURLConnection) url2.openConnection();
            con.connect();
            con.disconnect();
        } catch (MalformedURLException e) {
            System.out.println(e);
        } catch (IOException e) {
            System.out.println(e);
        }
        long t2 = System.currentTimeMillis();
        return (int) (t2 - t1);
    }
    public static void main(String[] args) throws Exception {
        System.setProperty( "sun.net.client.defaultConnectTimeout", "100");
        System.out.println(test("http://www.dr.dk/"));
    }
}
