zoukankan      html  css  js  c++  java
  • 禁用Java DNS缓存-Disable DNS caching

    Once an application has performed network access (i.e. urlconnection, parsing of xml document with external references, etc), the DNS settings get cached so any subsequent operation will use the old settings even if the real settings have changed. To reset everything, you have to restart the server since the the default setting JVM setting is to cache forever.

    There are 4 properties that can be used to override the default behaviour.

    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".
    
    networkaddress.cache.negative.ttl (default: 10)
        Specified in java.security to indicate the caching policy for un-successful
        name lookups from the name service. The value is specified as as integer to 
        indicate the number of seconds to cache the failure for un-successful lookups.
    
        A value of 0 indicates "never cache". A value of -1 indicates "cache forever". 
    
    sun.net.inetaddr.ttl
        This is a sun private system property which corresponds to networkaddress.cache.ttl. 
        It takes the same value and has the same meaning, but can be set as a command-line 
        option. However, the preferred way is to use the security property mentioned above. 
    
    sun.net.inetaddr.negative.ttl
        This is a sun private system property which corresponds to networkaddress.cache.negative.ttl. 
        It takes the same value and has the same meaning, but can be set as a command-line option. 
        However, the preferred way is to use the security property mentioned above.
    

    So you can disable caching by adding -Dsun.net.inetaddr.ttl=0 on the command line starting the JVM. But you can't set the value of networkaddress.cache.ttl on the command line. You can set the required value in the java.security file located in %JRE%libsecurity

    networkaddress.cache.ttl=60
    networkaddress.cache.negative.ttl=10
    

    or set the value in your code with

    java.security.Security.setProperty("networkaddress.cache.ttl" , "0");
    
  • 相关阅读:
    微信红包限额提升方法
    微信从业人员推荐阅读的100本经典图书
    微信裂变红包
    微信公众平台开发最佳实践(第2版)
    微信公众平台开发(108) 微信摇一摇
    微信支付样例
    微信行业解决方案
    牛逼顿
    微信支付开发(4) 扫码支付模式二
    微信公众平台开发(107) 分享到朋友圈和发送给好友
  • 原文地址:https://www.cnblogs.com/diyunpeng/p/3637573.html
Copyright © 2011-2022 走看看