Java Web Start的造成执行缓慢 [英] Java Web Start causing slow execution

查看:1472
本文介绍了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文件读取解析它的特定操作。这是code线:

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 Start的)

(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-架构-1.0.jar 库文件)。所以,我的问题是:假设它是库的大小,有没有什么办法,以prevent呢?我已经库缓存通过控制面板打开的,因此为什么它似乎需要是缓存库?一旦它被加载,速度非常快。但它永远是第一次。

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做它开始用了约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.

有在的POI的Bugzilla(错误51660) 。

我解决了这个通过下载 XMLBeans的 2.5.0版,而是包括了的的xmlbeans-2.3 .0.jar 的我包括的 xbean.jar 的和的 jsr173_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天全站免登陆