JVM内置URL缓存在访问添加的jar时会导致Jetty出现间歇性问题。
例外情况如下:
java.lang.IllegalStateException: zip file closed
at java.util.zip.ZipFile.ensureOpen(ZipFile.java:669) ~[na:1.8.0_71]
at java.util.zip.ZipFile.getEntry(ZipFile.java:309) ~[na:1.8.0_71]
at java.util.jar.JarFile.getEntry(JarFile.java:240) ~[na:1.8.0_71]
at java.util.jar.JarFile.getJarEntry(JarFile.java:223) ~[na:1.8.0_71]
at sun.misc.URLClassPath$JarLoader.getResource(URLClassPath.java:1005) ~[na:1.8.0_71]
at sun.misc.URLClassPath$JarLoader.findResource(URLClassPath.java:983) ~[na:1.8.0_71]
at sun.misc.URLClassPath.findResource(URLClassPath.java:188) ~[na:1.8.0_71]
at java.net.URLClassLoader$2.run(URLClassLoader.java:569) ~[na:1.8.0_71]
at java.net.URLClassLoader$2.run(URLClassLoader.java:567) ~[na:1.8.0_71]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_71]
at java.net.URLClassLoader.findResource(URLClassLoader.java:566) ~[na:1.8.0_71]
如果通过将以下XML片段添加到相应的Jetty配置(jetty.xml)文件来禁用JVM缓存,则可以解决此问题。
<Set class="org.eclipse.jetty.util.resource.Resource" name="defaultUseCaches">false</Set>
如果我们使用Jetty禁用JVM缓存,对应用程序性能有什么影响?