简体   繁体   中英

Java - .jar file runs out of heap but executing in eclipse doesn't

I am currently working on a GUI-App with javafx which displays the content of some excel files (around 3MB of size total). I am using apache POI to load excel file data which I then store in some custom objecs. If I am running the app from eclipse, everything works fine. If I build it as a .jar with maven, I get an out of heap error and I have to set -Xmx512M so that the app works properly without crashes.

I just noticed, that my program occupies 1GB of RAM running in eclipse and around 580MB running as jar with the setting set metioned above.

I don't know why my program needs so much RAM even though it effectively contains only 3MB of actual information.

I am even using the file-method from apache POI to reduce memory consumption:

final URL path = this.getClass().getClassLoader().getResource(filename);
final File f;
if(path.getPath().contains(".jar"))
    f = new File(filename);
else
    f = new File(path.getFile());
final Workbook workbook = WorkbookFactory.create(f);
...

try running your program with the xmx parameter set to at least 1GB, since you know it consumes as much.

java -Xmx 2048

Your program might only have 3MB of information. But your program could easily have operations to duplicate this information or otherwise transform it and become 1000 times larger than the original data. You might try to optimize your program by freeing resources manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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