JAVA - 在jxl中编写Excel单元格时出现内存不足错误 [英] JAVA - Out Of Memory Error while writing Excel Cells in jxl
问题描述
我正在使用JXL编写一个50000行和30列的Excel文件。
我的代码看起来像这样:
I am using JXL to write an excel file of 50000 rows and 30 columns. My code looks like this:
for(int j = 0; j< countOfRows; j ++){
for (int j = 0; j < countOfRows; j++) {
myWritableSheet.addCell(new Label(0, j, myResultSet.getString(1), myWritableCellFormat));
myWritableSheet.addCell(new Label(1, j, myResultSet.getString(2), myWritableCellFormat));
.....
.....
}
在编写单元格时,程序变得越来越慢
While writing the cells, the program goes slower and slower
行25000我收到以下错误:
and finally around the row 25000 I am getting the following error:
线程Thread-3中的异常java.lang.OutOfMemoryError:Java堆空间
在jxl.write.biff.WritableSheetImpl.getRowRecord(WritableSheetImpl.java:984)
在jxl.write.biff.WritableSheetImpl.addCell(WritableSheetImpl.java:951)
在KLL.ConverterMainFrame $ exportToXLSBillRightsThread.run( ConverterMainFrame.java:6895)
Java处理内存总是很困难。
It's always difficult in Java to handle the memory.
在这种情况下,这似乎是jxl的问题。
In this case it seems to be the jxl's problem.
有没有办法写入文件,清除内存并使每1000个单元格写入单元格?
Is there a way to write the file, clear the memory and coninue writing cells every 1000 cells?
这是一个好主意,还是还有什么建议作为一个解决方案?
Would that be a good idea or what else would you propose as a solution?
推荐答案
p>是rai将虚拟机可用的内存(使用-Xms和-Xmx)命名为不可选项?
Is raising the memory available to the VM (with -Xms and -Xmx) not an option?
这篇关于JAVA - 在jxl中编写Excel单元格时出现内存不足错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!