the JVM will cache the dns information for me automatically after the first query
也就是说,httpclient去抓取每个url时,JVM都会自动cache住 这个url和对应的ip,并且是永远cache住,除非cache住的内容大于 JVM的限制 ,如果将来这个url(域名)更换了ip,httpclient会首先去JVM的cache里取,如果取到了。直接根据这个ip去抓取。
所以往往某个域名更换了IP,抓取结果都是604错误。
解决办法:
networkaddress.cache.ttl (default: -1)
Specified in java.security to indicate the caching policy for successful
name lookups from the name service. The value is specified as as integer
to indicate the number of seconds to cache the successful lookup.
A value of -1 indicates "cache forever".
所以只需在java代码里添加:
- java.security.Security.setProperty("networkaddress.cache.ttl" , "0");
本文探讨了JVM如何自动缓存DNS信息,并提供了解决因DNS缓存导致的抓取错误的方法。通过调整Java安全属性networkaddress.cache.ttl,可以有效避免因域名IP更改而引发的问题。
3026

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



