tags:

views:

1152

answers:

2

We use GSLB for geo-distribution and load-balancing. Each service is assigned a fixed domain name. Through some DNS magic, the domain name is resolved into an IP that's closest to the server with least load. For the load-balancing to work, the application server needs to honor the TTL from DNS response and to resolve the domain name again when cache times out. However, I couldn't figure out a way to do this in Java.

The application is in Java 5, running on Linux (Centos 5).

+2  A: 
Byron Whitlock
Note: this doesn't disable all DNS caching in your OS. Just disables Java's own broken in-memory caching in the library.You can simply set these properties on the command line when you invoke the JVM.
Nelson
I don't know that "broken" is valid. Java (for security reasons) caches DNS entries forever, or until the JVM is restarted, whichever comes first. This (from what I can tell) was by design. The settings can be made in the java.security policy file, or at the command line. The settings are different for each. Reference: http://www.rgagnon.com/javadetails/java-0445.html
Milner
+2  A: 

To expand on Byron's answer, I believe you need to edit the file java.security in the %JRE_HOME%\lib\security directory to effect this change.

Here is the relevant section:

#
# The Java-level namelookup cache policy for successful lookups:
#
# any negative value: caching forever
# any positive value: the number of seconds to cache an address for
# zero: do not cache
#
# default value is forever (FOREVER). For security reasons, this
# caching is made forever when a security manager is set. When a security
# manager is not set, the default behavior is to cache for 30 seconds.
#
# NOTE: setting this to anything other than the default value can have
#       serious security implications. Do not set it unless 
#       you are sure you are not exposed to DNS spoofing attack.
#
#networkaddress.cache.ttl=-1

Documentation on the java.security file here.

matt b