简体   繁体   English

Apache POI 在导出可运行 Jar 时极其缓慢

[英]Apache POI extremely slow when exporting Runnable Jar with Package option in Eclipse

I have performance problems with Apache POI when reading excel files when I export the runnable jar with the Package option from eclipse, not with the Extract required libraries into generated JAR option. I have performance problems with Apache POI when reading excel files when I export the runnable jar with the Package option from eclipse, not with the Extract required libraries into generated JAR option.

In order to show you the problem, I have created a minimal program.为了向您展示问题,我创建了一个最小程序。 The build.gradle file is: build.gradle 文件为:

plugins {
    id 'java'
}

sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
     compile group: 'org.apache.poi', name: 'poi-ooxml', version: '4.1.2'
}

and the App.java file:和 App.java 文件:

import java.io.File;
import java.io.FileInputStream;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class App {

     public static void main(final String[] args) {
        final String excelPath = System.getProperty("user.dir") + "/libro.xlsx"  ;
        try {
            final FileInputStream fis = new FileInputStream(new File(excelPath));
            
            
            final long TIMER = System.currentTimeMillis();
            System.out.println(  "start") ;
            XSSFWorkbook wb = new XSSFWorkbook( fis );
            wb.close();
            System.out.println( "end : " + ( System.currentTimeMillis() - TIMER) + " msec" ) ;
            
            
        } catch (final Exception e) {
            System.out.println("error " + e.getMessage()) ; 
        }
    }
}

When I run the program with an empty excel file, I get the following results on the same machine and with the same files:当我使用空的 excel 文件运行程序时,我在同一台机器上使用相同的文件得到以下结果:

  • Generated with the Extract option:使用提取选项生成:

     C:\temp>java -jar prueba.jar start end: 603 msec
  • Generated with the Package option:使用 Package 选项生成:

     C:\temp>java -jar prueba.jar start end: 6015 msec

about 10 times more.大约10倍以上。

What could it be the problem and how can I fix it so that the execution times are similar?这可能是什么问题,我该如何解决它以使执行时间相似?

Could anyone help me to find the problem and solve it?谁能帮我找到问题并解决它?

Thank you in advance.先感谢您。

You can look at the difference between the two files using jar tf followed by the archive.您可以使用jar tf后跟存档查看两个文件之间的差异。 It may be that one of the archives is including the signed content, which will mean that upon load, the JVM will verify that the content is the same.可能其中一个档案包含签名的内容,这意味着在加载时,JVM 将验证内容是否相同。 You could perhaps see if there is a similar execution time when running with -Xverify:none , although I'd recommend against doing that in a production system.您可能会看到使用-Xverify:none运行时是否有类似的执行时间,尽管我建议不要在生产系统中这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM