如何在 Web Start 应用程序中设置 Java DNS 解析器缓存 TTL?
我可以告诉 Java DNS 解析器不要像这样缓存:
java.security.Security.setProperty("networkaddress.cache.ttl", "0");
当程序直接从 JRE 运行时,这工作得很好,但是,当从 Web Start 运行时,此设置似乎会被忽略,并且它会永远缓存。我没有收到 SecurityException。
但是,如果我将安全管理器设置为空,则该设置将在 Web Start 中起作用:
System.setSecurityManager(null);
有谁知道在 Web Start 中启用此属性而不关闭安全管理器的方法吗?另外,如果您能更多地了解正在发生的事情,我将不胜感激。
I am able to tell the Java DNS resolver not to cache like this:
java.security.Security.setProperty("networkaddress.cache.ttl", "0");
This works just fine when the program is run directly from the JRE, however, when run from Web Start, this setting seems to be ignored, and it caches forever. I don't get a SecurityException.
However, if I set the security manager to null, the setting will work in Web Start:
System.setSecurityManager(null);
Does anybody know a way to enable this property in Web Start without turning off the Security Manager? Also, if you can simply shed more light on what's going on, I'd appreciate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简单的答案是,考虑到您指定的属性,
sun.net.InetAddressCachePolicy
仅在静态初始化程序中初始化一次。{} Webstart 加载程序显然使用了该类,因此它不会占用您的值。但是,由于该属性可能未初始化,因此您可以使用
InetAddressCachePolicy.setIfNotSet(InetAddressCachePolicy.NEVER)
。或者,可以将系统属性添加到 jnlp:
< property name="com.sun.net.inetaddr.ttl" value="0" />
如果 webstart 已指定(尚未测试),则只能通过反射进行黑客攻击
字段 f= InetAddressCachePolicy.getDeclaredField("cachePolicy"); f.setAccessible(true); f.setInt(0);
这可能有效,也可能无效。祝你好运,黑客快乐!
The simple answer is that
sun.net.InetAddressCachePolicy
is initialized only once in the static{} initializer taking into account the property you specify. Webstart loader obviously uses the class, hence it doesn't take your value.However, since the property may not be initialized you can use
InetAddressCachePolicy.setIfNotSet(InetAddressCachePolicy.NEVER)
.Alternatively there is a system property to add to the jnlp:
< property name="com.sun.net.inetaddr.ttl" value="0" />
If it is specified already by the webstart (have not tested) you can resort only on hacking via reflection
Field f= InetAddressCachePolicy.getDeclaredField("cachePolicy"); f.setAccessible(true); f.setInt(0);
which may or may not work.Good luck and happy hacking!
你用javaws运行这个吗?如果是的话,你尝试过吗
Are you running this with javaws? If you are, have you tried