Java Web Start 导致执行缓慢 [英] Java Web Start causing slow execution

查看:71
本文介绍了Java Web Start 导致执行缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Java Web Start 部署的应用程序.在进行单元测试时,我注意到一个小问题:每当我的应用程序使用 Java Web Start 运行时,特定操作需要很长时间才能执行.但是,在本地运行时,速度非常快.

I have an application that I'm deploying with Java Web Start. When I was doing unit testing, I noticed a slight problem: whenever my application is run with Java Web Start, a particular operation takes a long time to execute. When run locally, however, it is quite fast.

我正在谈论的特定操作是读取大型(5k 行)Excel 文件以对其进行解析.这是代码行:

The particular operation I'm talking about is reading in a large (5k row) Excel file to parse it. This is the line of code:

Workbook wb = WorkbookFactory.create(new FileInputStream(new File(inputFile.getText())));

为了解决问题,我添加了一种记录时间的方法:

To figure out the problem, I added a way to record the time:

long time1 = System.currentTimeMillis();
Workbook wb = WorkbookFactory.create(new FileInputStream(new File(inputFile.getText())));
long time2 = System.currentTimeMillis();
long diff = time2 - time1;
double seconds = (double)diff / (double)1000;
DecimalFormat df = new DecimalFormat("#,##0.00");
System.out.println("Elapsed Time: " + df.format(seconds) + " seconds.");

这是输出:

(本地)

Elapsed Time: 4.83 seconds.

(Java Web 开始)

(Java Web Start)

Elapsed Time: 35.52 seconds.

但是,随后立即运行(在 Java Web Start 上)会产生以下结果:

BUT THEN, an immediate subsequent run (on Java Web Start) yields this:

Elapsed Time: 1.61 seconds.

我怀疑这与 POI 库有关(特别是读取 POI 所需的库的大小,更具体地说,是 13 MB ooxml-schemas-1.0.jar 库文件).所以,我的问题是:假设它是库大小,有什么办法可以防止这种情况发生?我通过控制面板打开了库缓存,为什么它似乎需要缓存库?加载后,速度很快.但它需要永远的第一次.

My suspicion is that this has to do with the POI library (in particular, the size of the library required to read POI, more specifically, the 13 MB ooxml-schemas-1.0.jar library file). So, my question is: assuming it is the library size, is there any way to prevent this? I have library caching turned on through the control panel, so why does it seem to need to be caching the library? Once it is loaded, it's fast. But it takes forever the first time.

这是控制面板的图像,显​​示我允许它存储库:

Here's an image of the control panel showing that I am allowing it to store the libraries:

有没有人见过这种行为?没有 SSCCE,因为...好吧,您如何发布带有 Java Web Start 问题的 SSCCE?

Has anyone seen this kind of behavior before? No SSCCE because... well, how do you post an SSCCE with a Java Web Start question?

推荐答案

我遇到了类似的问题,但从文件加载 .docx 文档 (XWPFDocument).在本地执行时,加载文件不到 1 秒;然而,通过 Java Web Start 完成它对我来说需要大约 35 秒,对我的同事来说甚至需要半小时.这是我解决它的方法,希望它也能解决这个问题.

I had a similar issue but with loading a .docx document (XWPFDocument) from a file. While doing it locally, it took under 1 second to load the file; however, doing it via Java Web Start it took around 35 seconds for me, and even half an hour for my colleague. Here's how I got it solved, hopefully it might solve this issue as well.

罪魁祸首是 Apache XMLBeans 库,或者说它在 Apache POI 中的使用方式不正确.Apache POI 版本中包含的 XMLBeans 库是 2.3.0 版,jar 文件是 xmlbeans-2.3.0.jar.如果在本地启动程序时将它包含在类路径中,它会正常工作.但是,如果您将它作为资源包含在 .jnlp 文件中并使用 Web Start 启动您的程序,它会按照您的解释运行得很慢.如果您打开 Java 控制台并将跟踪级别设置为 5,您将看到当您加载 .docx 文件时,程序将查找资源 xbean.jar 即使您可能没有甚至在你的 .jnlp 文件中有这个.这会导致程序寻找资源直到超时,并且可能会重试多次,导致加载时间变慢.

The culprit was the Apache XMLBeans library, or rather the incorrect way it has been used in Apache POI. The XMLBeans library included with the Apache POI release is version 2.3.0 and the jar file is xmlbeans-2.3.0.jar. If you include this in your classpath while launching a program locally, it'll work just fine. However, if you include it in your .jnlp file as a resource and launch your program with Web Start, it'll work really slowly as you explained. If you open the Java Console and set trace level to 5, you'll see that when you load the .docx file, the program will look for a resource xbean.jar even though you probably don't even have this in your .jnlp file. This will cause the program to look for the resource until it times out, and probably will try again many times, causing the slow loading time.

2011 年的 POI Bugzilla(错误 51660)中有关于此的错误报告.

我通过下载 XMLBeans 2.5.0 版而不是包含 xmlbeans-2.3 解决了这个问题.0.jar 我将 xbean.jarjsr173_1.0_api.jar 包含在类路径中,并作为 .jnlp 文件中的资源.

I solved this by downloading XMLBeans version 2.5.0 and instead of including the xmlbeans-2.3.0.jar I included the xbean.jar and jsr173_1.0_api.jar in the classpath and as resources in the .jnlp file.

这篇关于Java Web Start 导致执行缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆