URLConnection getConnectTimeout Example
URLConnection class getConnectTimeout example. This example shows you how to use getConnectTimeout method.
URLConnection class getConnectTimeout example. public int getConnectTimeout() Returns setting for connect timeout. 0 return implies that the option is disabled (i.e., timeout of infinity).
Here is the code
/*
* @ # GetConnectTimeout.java
* A class repersenting use to getConnectTimeout
* method of URLConnection class in java.net package
* version 23 June 2008
* author Rose India
*/
import java.net.*;
public class GetConnectTimeout {
public static void main(String args[]) throws Exception {
URL url = new URL("http://localhost:8080/net/listnets.jsp");
URLConnection connection = url.openConnection();
System.out.println("ConnectTimeout " + connection.getConnectTimeout());
connection.setConnectTimeout(10);
System.out.println("ConnectTimeout " + connection.getConnectTimeout());
}
} |
Output
ConnectTimeout 0
ConnectTimeout 10 |
|