我注意到,当执行 Java Applet 时,类加载器似乎会向 Web 服务器发出大量请求,这些请求本应包含在 Applet 的 jar 文件中,或者没有人需要。类、属性文件、小程序中每个类的 BeanInfo,凡是您能想到的。看起来这实际上是完全有意的,显然应该允许为 jar 中的各个文件提供更新,而不必替换整个 jar - 因此类加载器首先尝试远程检索文件,并且只有在失败时才设计使用它已经有本地副本。
我发现网络服务器不断受到它不得不拒绝的无用请求的打击,这非常烦人和浪费。是否有办法反转默认行为,即告诉类加载器首先使用本地副本,并且只有在本地找不到所需资源时,才尝试远程获取它?是否过于希望我只需要设置某种系统属性,或者我实际上必须编写一个替换类加载器来完成此任务?
I've noticed that when a Java Applet is executed, the classloader seems to be hitting the web server with a literal deluge of requests for stuff that should already be in the applet's jar file, or stuff that nobody needs. Classes, properties files, BeanInfo for each and every class in the applet, you name it. It seems this is actually fully intentional, apparently supposed to allow for providing updates to individual files within the jar without having to replace the entire jar - so the classloader first tries to retrieve the file remotely, and only if that fails it deigns to use the local copy it already has.
I find that highly annoying and wasteful, the web server keeps getting hammered by useless requests it has to deny. Isn't there a way to invert the default behaviour, i.e. to tell the class loader to use the local copy first and only once the desired resource can't be found locally, try to fetch it remotely? Would it be too much to hope for that there might some kind of system property I just have to set, or do I actually have to write a replacement class loader to accomplish this?
发布评论
评论(1)
应首先从档案中读取文件。为了抑制应该失败的松散文件查找,有一个选项:
http://download.oracle.com/javase/6/docs/technotes/guides/plugin/developer_guide/special_attributes.html#codebase
Files should be read from the archives first. To suppress loose file lookups that should fail, there is an option for that:
http://download.oracle.com/javase/6/docs/technotes/guides/plugin/developer_guide/special_attributes.html#codebase