In response to a Byron request, you cannot set networkaddress.cache.ttl or networkaddress.cache.negative.ttl as system properties using the -D flag or calling System.setProperty because they are not system properties - they are security properties.
If you want to use the System property to trigger this behavior (so you can use the -D flag or call System.setProperty ), you need to set the following System property:
-Dsun.net.inetaddr.ttl=0
This system property will give the desired effect.
But keep in mind: if you do not use the -D flag when starting the JVM process and decide to call it from the code instead:
java.security.Security.setProperty("networkaddress.cache.ttl" , "0")
This code must be executed before any other code in the JVM attempts to perform network operations.
This is important because, for example, if you called Security.setProperty in a .war file and deployed this .war for Tomcat, this would not work: Tomcat uses the Java network stack to initialize much earlier than yours. the military code is being executed. Because of this โrace condition," it is usually more convenient to use the -D flag when starting the JVM process.
If you do not use -Dsun.net.inetaddr.ttl=0 or call Security.setProperty , you will need to edit $JRE_HOME/lib/security/java.security and set these security properties in this file, for example.
networkaddress.cache.ttl = 0 networkaddress.cache.negative.ttl = 0
But pay attention to the security warnings in the comments related to these properties. Do this only if you are confident that you are not vulnerable to DNS spoofing attacks .
Les Hazlewood Jun 20 '13 at 16:50 2013-06-20 16:50
source share