Java has some seriously weird dns caching behavior. Your best bet is to turn off dns caching or set it to some low number like 5 seconds.
Ttl (默认值: -1)
Indicates the caching policy for successful name lookups from the name service. The value is specified as as integer to indicate the number of seconds to cache the successful lookup. A value of -1 indicates "cache forever".
#
# 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
IBM 有一篇关于 WebSphere 如何处理 DNS 缓存 给你的相当详细的文章。与上述内容相关的是:
要禁用 Web 服务的地址缓存,需要将另外一个 JVM 自定义属性 disableWSAddressCache 设置为 true。使用此属性可禁用 Web 服务的地址缓存。如果系统通常使用大量客户端线程运行,并且在 wsAddrCache 缓存上遇到锁争用,则可以将此自定义属性设置为 true,以防止缓存 Web 服务数据。
#networkaddress.cache.ttl=-1 <- this line is commented out
networkaddress.cache.negative.ttl=10
BTW if the networkaddress.cache.negative.ttl is not set (removed from the file) the default inside the java class is 0. Documentation is wrong in this regard. This is what tripped me over.