简体   繁体   English

Apache POI autoColumnWidth java.lang.OutOfMemoryError:超出GC开销限制

[英]Apache POI autoColumnWidth java.lang.OutOfMemoryError: GC overhead limit exceeded

Am getting the OutOfMemoryError when the autoColumnWidth function is called on all the columns in my excel containing 1,28,237 rows and 20 columns.当在我的 excel 中包含 1,28,237 行和 20 列的所有列上调用autoColumnWidth函数时,我收到OutOfMemoryError Am using SXSSF api and allocating -Xms2048m -Xmx4096m -XX:PermSize=1024m -XX:MaxPermSize=2048m to JVM but still no success.我正在使用SXSSF api 并将-Xms2048m -Xmx4096m -XX:PermSize=1024m -XX:MaxPermSize=2048m给 JVM,但仍然没有成功。 CPU utilization goes upto 100% , my system RAM is 6gb which is used upto 5.8gb during the process and then i get OutOfMemoryError . CPU 利用率高达 100%,我的系统 RAM 为 6gb,在此过程中最多使用 5.8gb,然后我得到OutOfMemoryError Any solution to it ?有什么解决办法吗?

With this, I can think of one solution ie taking a variable for each column, finding the max length and in the end after all data is entered set the column to respective variable.有了这个,我可以想到一个解决方案,即为每列取一个变量,找到最大长度,最后在输入所有数据后将列设置为相应的变量。

Any other solution?还有其他解决办法吗?

My Code To Create Excel我的代码来创建 Excel

public static void createVideodataExcelFile(String excelPath, int maxRiskArea){

    FileOutputStream fileOut = null;
    XSSFWorkbook workbook = new XSSFWorkbook();

    CellStyle style = workbook.createCellStyle();
    XSSFFont font = workbook.createFont();
    font.setColor(HSSFColor.BLACK.index);
    font.setBold(true);
    style.setFont(font);
    int cellCount = 0;

    try {
        File file = new File(excelPath);

        if(file.createNewFile()){
            SXSSFWorkbook wb = new SXSSFWorkbook(workbook); 
            wb.setCompressTempFiles(true);
            Sheet sheet = wb.createSheet("GLE Video Data");
            int rowCount = sheet.getPhysicalNumberOfRows();
            //System.out.println("Row Count ="+rowCount);
            Row row = sheet.createRow(rowCount);

            Cell cell1 = row.createCell(cellCount);
            createCell(cell1, row, "CourseContent name", style, cellCount);
            createCell(cell1, row, "lang", style, ++cellCount);
            createCell(cell1, row, "CourseTitle", style, ++cellCount);
            createCell(cell1, row, "Audience", style, ++cellCount);
            createCell(cell1, row, "ContentRegion", style, ++cellCount);
            createCell(cell1, row, "CourseTitle", style, ++cellCount);
            createCell(cell1, row, "DeprecatedId", style, ++cellCount);
            createCell(cell1, row, "GleCode", style, ++cellCount);
            createCell(cell1, row, "Guid", style, ++cellCount);
            createCell(cell1, row, "LearningFormat", style, ++cellCount);

            for(int i = 0 ; i < maxRiskArea ; ++i){
                createCell(cell1, row, "RiskArea", style, ++cellCount);
            }

            createCell(cell1, row, "SalesforceId", style, ++cellCount);
            createCell(cell1, row, "Setting", style, ++cellCount);
            createCell(cell1, row, "SmsCode", style, ++cellCount);
            createCell(cell1, row, "pageID", style, ++cellCount);
            createCell(cell1, row, "title", style, ++cellCount);
            createCell(cell1, row, "ID", style, ++cellCount);
            createCell(cell1, row, "media_src", style, ++cellCount);
            createCell(cell1, row, "cuePoint", style, ++cellCount);
            createCell(cell1, row, "character", style, ++cellCount);
            createCell(cell1, row, "line", style, ++cellCount);

            fileOut = new FileOutputStream(excelPath);
            wb.write(fileOut);
            System.out.println("Excel Of GLE Data Created.");
        }


    } catch (IOException e) {
        errorLog.error("Excel Read/Write Error ="+e.getMessage());
        throw new GLEException(e);
    }
    finally{
        try {
            if(fileOut!=null)
            fileOut.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            errorLog.error("Excel Read/Write Error ="+e.getMessage());
            throw new GLEException(e);      

        }
    }
}

private static void createCell(Cell cell , Row row, String name, CellStyle style, int cellCount ){
    cell = row.createCell(cellCount);
    cell.setCellStyle(style);
    cell.setCellValue(name);
}

尝试在调用 autoSizeColumn(columnIndex) 之前在 SXSSFSheet 对象上调用 trackAllColumnsForAutoSizing() 它将被修复

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java-Apache poi导致java.lang.OutOfMemoryError:超出了GC开销限制 - Java - Apache poi leads to java.lang.OutOfMemoryError: GC overhead limit exceeded java.lang.OutOfMemoryError:使用Apache POI读取Excel文件时,超出了GC开销限制 - java.lang.OutOfMemoryError: GC overhead limit exceeded" while reading excel file using apache POI java.lang.OutOfMemoryError:超出GC开销限制,通过Apache POI读取启用宏的Excel工作表时出错 - java.lang.OutOfMemoryError: GC overhead limit exceeded Error while Reading Macro enabled excel sheet through Apache POI Java PreparedStatement java.lang.OutOfMemoryError:超出了GC开销限制 - Java PreparedStatement java.lang.OutOfMemoryError: GC overhead limit exceeded 詹金斯 java.lang.OutOfMemoryError:超出 GC 开销限制 - Jenkins java.lang.OutOfMemoryError: GC overhead limit exceeded java.lang.OutOfMemoryError:GC开销限制超出了android studio - java.lang.OutOfMemoryError: GC overhead limit exceeded android studio Gridgain:java.lang.OutOfMemoryError:超出了GC开销限制 - Gridgain: java.lang.OutOfMemoryError: GC overhead limit exceeded Spark失败了java.lang.OutOfMemoryError:超出了GC开销限制? - Spark fails with java.lang.OutOfMemoryError: GC overhead limit exceeded? SonarQube java.lang.OutOfMemoryError:超出了GC开销限制 - SonarQube java.lang.OutOfMemoryError: GC overhead limit exceeded Tomcat java.lang.OutOfMemoryError:超出了GC开销限制 - Tomcat java.lang.OutOfMemoryError: GC overhead limit exceeded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM