How to read large(95+MB) excel workbook with more then 10 sheets in java using POI library without increasing JVM(like -Xmx1G). If we run jar file without increasing VM got OutOfMemory error. How can I optimize this issue in coding itself instead of increasing VM?
如何在不增加JVM(比如-Xmx1G)的情况下,使用POI库读取大型(95+MB)的excel工作簿,并使用POI库使用更多的10个表。如果我们在不增加VM的情况下运行jar文件,就会产生OutOfMemory错误。如何优化这个问题而不是增加VM?
1 个解决方案
#1
5
There are no clever "optimizations" that will allow you to continue with your current approach and run using less memory.
没有任何聪明的“优化”可以让您继续使用当前的方法并使用更少的内存运行。
You are going to need to change your program so that it does not load the entire workbook into memory.
您将需要更改您的程序,以便它不会将整个工作簿加载到内存中。
As @M.Deinum points out, Apache POI provides an alternative way to process Excel files where you get a sequence of parser events rather than an in-memory representation of each entire spreadsheet. Switching from the in-memory model to the event-based model will entail a significant amount of recoding of your application. But if you cannot afford the memory you have no other practical alternatives.
@M。Deinum指出,Apache POI提供了另一种方法来处理Excel文件,在那里您可以获得一个解析器事件序列,而不是每个完整的电子表格的内存中表示。从内存模型切换到基于事件的模型需要大量的重新编码应用程序。但是如果你负担不起这种记忆,你就没有其他的实际选择了。
#1
5
There are no clever "optimizations" that will allow you to continue with your current approach and run using less memory.
没有任何聪明的“优化”可以让您继续使用当前的方法并使用更少的内存运行。
You are going to need to change your program so that it does not load the entire workbook into memory.
您将需要更改您的程序,以便它不会将整个工作簿加载到内存中。
As @M.Deinum points out, Apache POI provides an alternative way to process Excel files where you get a sequence of parser events rather than an in-memory representation of each entire spreadsheet. Switching from the in-memory model to the event-based model will entail a significant amount of recoding of your application. But if you cannot afford the memory you have no other practical alternatives.
@M。Deinum指出,Apache POI提供了另一种方法来处理Excel文件,在那里您可以获得一个解析器事件序列,而不是每个完整的电子表格的内存中表示。从内存模型切换到基于事件的模型需要大量的重新编码应用程序。但是如果你负担不起这种记忆,你就没有其他的实际选择了。