JVM DNS IP地址缓存(InetAddress)

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

一、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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值