一、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 not desired, then a

本文介绍了JVM如何缓存IP地址,包括默认策略和自定义策略。默认情况下,正确解析的IP地址将永久缓存,错误解析的IP地址缓存10秒。自定义策略可以通过修改`java.security`文件、JVM启动参数或运行时使用`System`类进行调整。此外,文章还提出了使用单例模式操作`InetAddress`作为最佳实践。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



