一、JVM IP地址缓存
1. JVM默认策略
IP地址解析后缓存,LDNS、浏览器以及OS的hosts文件都会解析后缓存,因为一次DNS解析相对而言还是很耗时的。为了提高性能,JVM也会这么干。java.net.InetAddress类是IP地址的抽象,因此JVM对IP地址的默认缓存策略可以参看该类的注释。
InetAddress Caching
The InetAddress class has a cache to store successful as well as unsuccessful host name resolutions.
By default, when a security manager is installed, in order to protect against DNS spoofing attacks, the result of positive host name resolutions are cached forever. When a security manager is not installed, the default behavior is to cache entries for a finite (implementation dependent) period of time. The result of unsuccessful host name resolution is cached for a very short period of time (10 seconds) to improve performance.
If the default behavior is n