Reputation: 1436
We have an application which connects to the different applications using hostname. If I change the DNS server of the system on which the application is running, the application starts to fail with "java.net.UnknownHostException". But from the system I can send ping requests to different applications using FQDN. To take effect of DNS server change, we have to restart the application.
Is there any way in Java where we can refresh the DNS server details at runtime ?
Upvotes: 1
Views: 2208
Reputation: 4643
You can turn off dns caching for Java with 3 solutions:
Solution 1:
Start your program with this flag:
-Dsun.net.inetaddr.ttl=0
Solution 2:
At top of your java code use setProperty
java.security.Security.setProperty("networkaddress.cache.ttl" , "0")
Solution 3:
In $JRE_HOME/lib/security/java.security
set :
networkaddress.cache.ttl = 0
networkaddress.cache.negative.ttl = 0
Upvotes: 3