sun.net.client.defaultConnectTimeout Java System Property accepts an integer value representing the number of milliseconds-1
sun.net.client.defaultConnectTimeout OverviewThis property specifies the the default connect timeout (in milliseconds) for the protocol handler used by java.net.URLConnection.
The value of -1 means that it will wait indefinitely, there is no timeout.
This property does not control the connect timeout of all Sockets, only those used by java.net.URLConnection. For sockets created your own code, you can use the timeout argument in the Socket connect method to control the connect timeout.
The sun.net.client.defaultReadTimeout system property is related to the sun.net.client.defaultConnectTimeout property, it represents how long it will wait for a response.
Here are some other networking Java system properties:
http.agenthttp.keepAlivehttp.maxConnectionshttps.protocolsjava.net.preferIPv4Stackjava.net.preferIPv6Addressesjava.net.useSystemProxiesjavax.net.debugjavax.net.ssl.trustStorejdk.net.hosts.filejdk.tls.client.protocolsjdk.tls.disabledAlgorithmsnetworkaddress.cache.negative.ttlnetworkaddress.cache.ttlsun.net.client.defaultReadTimeoutsun.net.inetaddr.ttlJava has supported the sun.net.client.defaultConnectTimeout system property since at least version 6, support may go back to even older versions of java.
sun.net.client.defaultConnectTimeout on StartupYou can set the sun.net.client.defaultConnectTimeout java system property during startup of the java runtime using the -D command line argument:
java -Dsun.net.client.defaultConnectTimeout=-1 MyAppMain
You may also be able to specify sun.net.client.defaultConnectTimeout via the JAVA_TOOL_OPTIONS environment variable:
JAVA_TOOL_OPTIONS=-Dsun.net.client.defaultConnectTimeout=-1
sun.net.client.defaultConnectTimeout at RuntimeYou can set sun.net.client.defaultConnectTimeout at runtime with the following Java code:
System.setProperty("sun.net.client.defaultConnectTimeout", "-1");
WARNING: Depending on the property and JVM version using
setPropertymay or may not work if the JDK Java class that uses this variable has already been loaded. The value of the sun.net.client.defaultConnectTimeout system property may be cached within an internal private static variable of the implementing class.
To read the value of sun.net.client.defaultConnectTimeout at runtime, you can use this Java code:
String propertyValue = System.getProperty("sun.net.client.defaultConnectTimeout");
if (propertyValue != null) {
System.out.println("sun.net.client.defaultConnectTimeout = " + propertyValue);
} else {
System.out.println("sun.net.client.defaultConnectTimeout was null");
}