我正在分析一个 java 小程序启动时间。我注意到每次请求来自 jar 的资源时,都会完全读取一个大小为 5MB 的巨大 jar。例如图像日志配置文件、I18N 文件等......它应该这样吗?是否可以跳到正确的点?是否可以只读取一次文件?如果我将切换到 cache_archiv_ex 并添加一个 preload 指令会有帮助吗?打开 jar 文件的示例:
java.io.FileInputStream.open(String)
java.io.FileInputStream.<init>(File)
com.sun.deploy.cache.DeployCacheHandler$2.run()
java.security.AccessController.doPrivileged(PrivilegedExceptionAction)
com.sun.deploy.cache.DeployCacheHandler.get(URI, String, Map)
sun.net.www.protocol.http.HttpURLConnection.plainConnect()
sun.net.www.protocol.http.HttpURLConnection.connect()
sun.net.www.protocol.http.HttpURLConnection.getInputStream()
sun.plugin.PluginURLJarFileCallBack.downloadJAR(URLConnection, boolean)
sun.plugin.PluginURLJarFileCallBack.access$000(PluginURLJarFileCallBack, URLConnection, boolean)
sun.plugin.PluginURLJarFileCallBack$2.run()
java.security.AccessController.doPrivileged(PrivilegedExceptionAction)
sun.plugin.PluginURLJarFileCallBack.retrieve(URL)
sun.net.www.protocol.jar.URLJarFile.retrieve(URL, URLJarFile$URLJarFileCloseController)
sun.net.www.protocol.jar.URLJarFile.getJarFile(URL, URLJarFile$URLJarFileCloseController)
sun.net.www.protocol.jar.JarFileFactory.get(URL, boolean)
sun.net.www.protocol.jar.JarURLConnection.connect()
sun.plugin.net.protocol.jar.CachedJarURLConnection.connect()
sun.plugin.net.protocol.jar.CachedJarURLConnection.getInputStream()
java.net.URL.openStream()
java.lang.ClassLoader.getResourceAsStream(String)
sun.plugin2.applet.Applet2ClassLoader.getResourceAsStream(String)
..
.. (real application code stack...)
..
..
java.awt.event.InvocationEvent.dispatch()
java.awt.EventQueue.dispatchEvent(AWTEvent)
java.awt.EventDispatchThread.pumpOneEventForFilters(int)
java.awt.EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter)
java.awt.EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component)
java.awt.EventDispatchThread.pumpEvents(int, Conditional)
java.awt.EventDispatchThread.pumpEvents(Conditional)
java.awt.EventDispatchThread.run()