[英]Is there any way to refresh DNS Server details of Java application at runtime?
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".
如果更改运行该应用程序的系统的DNS服务器,该应用程序将因“ java.net.UnknownHostException”而开始失败。 But from the system I can send ping requests to different applications using FQDN.
但是我可以从系统中使用FQDN将ping请求发送到不同的应用程序。 To take effect of DNS server change, we have to restart the application.
为了使DNS服务器更改生效,我们必须重新启动应用程序。
Is there any way in Java where we can refresh the DNS server details at runtime ? Java中有什么方法可以在运行时刷新DNS服务器详细信息?
You can turn off dns caching for Java with 3 solutions: 您可以使用3种解决方案关闭Java的dns缓存:
Solution 1: 解决方案1:
Start your program with this flag: 使用以下标志启动程序:
-Dsun.net.inetaddr.ttl=0
Solution 2: 解决方案2:
At top of your java code use setProperty
在您的Java代码顶部,使用
setProperty
java.security.Security.setProperty("networkaddress.cache.ttl" , "0")
Solution 3: 解决方案3:
In $JRE_HOME/lib/security/java.security
set : 在
$JRE_HOME/lib/security/java.security
设置:
networkaddress.cache.ttl = 0
networkaddress.cache.negative.ttl = 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.