读取Excel数据时出现outOfMemoryException
我正在尝试从大小为 100MB 的 Excel 文件(xlsx 格式)中读取数据。在读取 Excel 数据时,我遇到了 outOfMemoryException。尝试将 JVM 堆大小增加到 1024MB,但仍然没有用,而且我无法增加更多的大小。也尝试过运行垃圾收集,但没有用。任何人都可以帮助我解决我的问题。
谢谢 帕万·库马尔 OV S.
I am trying to read data from an excel file(xlsx format) which is of size 100MB. While reading the excel data I am facing outOfMemoryException. Tried by increasing the JVM heap size to 1024MB but still no use and I cant increase the size more than that. Also tried by running garbage collection too but no use. Can any one help me on this to resolve my issue.
Thanks
Pavan Kumar O V S.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,JVM 对当前进程可用的内存量设置上限,以防止失控进程吞噬系统资源并导致机器停止运行。当读取或写入大型电子表格时,JVM 可能需要比默认分配给 JVM 更多的内存 - 这通常表现为 java.lang.OutOfMemoryError。
对于命令行进程,您可以使用 -Xms 和 -Xmx 选项为 JVM 分配更多内存,例如。要分配 10 MB 的初始堆分配,可以使用 100 MB 作为上限:
您可以参考 http://www.andykhan.com/jexcelapi/tutorial.html#introduction 了解更多详情
By default a JVM places an upper limit on the amount of memory available to the current process in order to prevent runaway processes gobbling system resources and making the machine grind to a halt. When reading or writing large spreadsheets, the JVM may require more memory than has been allocated to the JVM by default - this normally manifests itself as a java.lang.OutOfMemoryError.
For command line processes, you can allocate more memory to the JVM using the -Xms and -Xmx options eg. to allocate an initial heap allocation of 10 MB, with 100 MB as the upper bound you can use:
You can refer to http://www.andykhan.com/jexcelapi/tutorial.html#introduction for further details