Reputation: 703
Oracle's documentation says following about cache ttl -
networkaddress.cache.ttl
Specified in java.security to indicate the caching policy for successful name lookups from the name service.. The value is specified as integer to indicate the number of seconds to cache the successful lookup.
How does this setting impact the way DNS gets resolved? I have two nodes behind geo load balancer to which I connect for a service. Now, if they switch to point to other two nodes and if the above setting is set to -1, would it still attempt to the earlier resolved DNS and attempt to go to the node that probably no longer exist? If I do not use security manager in that case does this setting have any value?
Thanks in advance.
Upvotes: 2
Views: 3204
Reputation: 982
Default behaviour of JVM is to cache forever(setting -1) if security manager is installed. So you have to explicitly set the ttl timeout so that reattempt for DNS resolution happens. You may set this property via security manager in your application startup (app level) or system level.
java.security.Security.setProperty("networkaddress.cache.ttl" , "10");
For system wide edit below file to include ttl to zero.
<JAVA_HOME>/jre/lib/security/java.security
networkaddress.cache.ttl=0
Without security manager: Usually default value depends os & jvm type. AWS uses 60sec, Refer this
PS: System level settings always override app level settings.
Upvotes: 4