Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用xls格式创建jasper报表时出现内存错误_Java_Jasper Reports - Fatal编程技术网

Java 使用xls格式创建jasper报表时出现内存错误

Java 使用xls格式创建jasper报表时出现内存错误,java,jasper-reports,Java,Jasper Reports,我正在使用jasper report创建报告。当我创建包含12000条记录的报告(pdf,xls)时,工作正常,但当我创建包含40000条记录的报告时,堆内存问题严重。问题只在于xls格式。pdf格式很好用。我的代码如下 Map hm = new HashMap(); JasperPrint print = null; JRSwapFileVirtualizer virtualizer = null; JRSwapFile swapFile = new JRSwapFile("D://"

我正在使用jasper report创建报告。当我创建包含12000条记录的报告(pdf,xls)时,工作正常,但当我创建包含40000条记录的报告时,堆内存问题严重。问题只在于xls格式。pdf格式很好用。我的代码如下

Map hm = new HashMap();
JasperPrint print = null;
JRSwapFileVirtualizer virtualizer = null;
    JRSwapFile swapFile = new JRSwapFile("D://", 2048, 1024);
virtualizer = new JRSwapFileVirtualizer(2,swapFile,true);
JRVirtualizationHelper.setThreadVirtualizer(virtualizer);
hm.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(
                    list);
JRExporter exporter = null;
            if (type.toUpperCase().equalsIgnoreCase(FileTypes.PDF.name())) {
                exporter = new JRPdfExporter();

            } else if (type.toUpperCase().equalsIgnoreCase(FileTypes.XLS.name())) {
                exporter = new JRXlsExporter();
            }

            if(exporter != null)
            {
                exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
                        outFileName);
                exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
                exporter.exportReport();
            }

我找到了这个问题的答案。我已经在xls文件中添加了IS_IGNORE_分页,因此它可以正常工作

Map hm = new HashMap();
JasperPrint print = null;
JRSwapFileVirtualizer virtualizer = null;
JRSwapFile swapFile = new JRSwapFile("D://", 2048, 1024);
virtualizer = new JRSwapFileVirtualizer(2,swapFile,true);
JRVirtualizationHelper.setThreadVirtualizer(virtualizer);
hm.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
if (type.toUpperCase().equalsIgnoreCase(FileTypes.XLS.name()))
{
    hm.put(JRParameter.IS_IGNORE_PAGINATION, new Boolean(false));
}
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(
                    list);
JRExporter exporter = null;
            if (type.toUpperCase().equalsIgnoreCase(FileTypes.PDF.name())) {
                exporter = new JRPdfExporter();

            } else if (type.toUpperCase().equalsIgnoreCase(FileTypes.XLS.name())) {
                exporter = new JRXlsExporter();
            }

            if(exporter != null)
            {
                exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
                        outFileName);
                exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
                exporter.exportReport();
            }