Java System Properties
Quick Reference Guide


networkaddress.cache.ttl Java Security Property

The networkaddress.cache.ttl Java Security Property accepts an integer value corresponding to the number of seconds to cache

Default Value

-1 or 30

The default value of networkaddress.cache.ttl is set to infinite or -1 when a security manager is enabled. When a security manager is not enabled it's default value is JVM implementation specific. In most cases around 30 seconds.

networkaddress.cache.ttl Explained

When Java resolves a a hostname into an IP address (for example by performing a DNS lookup) it will cache the value for a period of time determined by this setting.

Related Properties

The sun.net.inetaddr.ttl system property is an implementation specific private system property that corresponds to this Java Security Property.

Here are some other Java properties related to networking:

Supported Since

Java has supported the networkaddress.cache.ttl security property since at least version 6, support may go back to even older versions of java.

Setting / Reading networkaddress.cache.ttl at Runtime

You can set networkaddress.cache.ttl at runtime with the following Java code:

java.security.Security.setProperty("networkaddress.cache.ttl", "value");

Please note that the networkaddress.cache.ttl value needs to be specified early, before the internal java classes are loaded that might use this value otherwise it will be ignored.

To read the value of networkaddress.cache.ttl at runtime, you can use this Java code:

String propertyValue = java.security.Security.getProperty("networkaddress.cache.ttl");
if (propertyValue != null) {
    System.out.println("networkaddress.cache.ttl = " + propertyValue);
} else {
    System.out.println("networkaddress.cache.ttl was null");
}

Setting networkaddress.cache.ttl on Startup

Be aware that networkaddress.cache.ttl is not a Java System Property, it is a Java Security Property. Therefor you cannot set it from the command line using -Dnetworkaddress.cache.ttl. You have to set networkaddress.cache.ttl in the java.security properties file.