Java API Tutorial - Java URLConnection .setConnectTimeout (int timeout)








Syntax

URLConnection.setConnectTimeout(int timeout) has the following syntax.

public void setConnectTimeout(int timeout)

Example

In the following code shows how to use URLConnection.setConnectTimeout(int timeout) method.

import java.net.URL;
import java.net.URLConnection;
/*  w w w  .java  2s . c  o  m*/
public class Main {

  public static void main(String args[]) throws Exception {

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();
    
    uc.setConnectTimeout(1000);
    System.out.println(uc.getConnectTimeout());
  }

}

The code above generates the following result.