java web运行缓慢,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.

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.");

And this is the ouput:

(local)

Elapsed Time: 4.83 seconds.

(Java Web Start)

Elapsed Time: 35.52 seconds.

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

Elapsed Time: 1.61 seconds.

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:

7QwQq.png

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

解决方案

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.

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.

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值