获取java.lang.OutOfMemoryError:Jboss中超出了GC开销限制

时间:2014-06-11 07:37:32

标签: java struts2 apache-poi

我正在尝试使用Struts-2部署一个Web应用程序,该应用程序从两个Excel工作表中读取大约40mb文件的数据并更新它,我将它部署到Jboss-5但是我得到java.lang.OutOfMemoryError: GC overhead limit exceeded错误。

当我通过Netbeans运行我的简单Java应用程序时的相同脚本;最初我遇到了同样的问题但我通过将-Xmx值增加到2g来增加Java堆内存,然后脚本运行正常。

我尝试在Jboss中增加-Xmx值,但有些人再次投掷java.lang.OutOfMemoryError: GC overhead limit exceeded" error

以下是完整的堆栈跟踪。

java.lang.OutOfMemoryError: GC overhead limit exceeded
        at org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate.addMultipleBlanks(ValueRecordsAggregate.java:159)
        at org.apache.poi.hssf.record.aggregates.RowRecordsAggregate.<init>(RowRecordsAggregate.java:103)
        at org.apache.poi.hssf.model.InternalSheet.<init>(InternalSheet.java:208)
        at org.apache.poi.hssf.model.InternalSheet.createSheet(InternalSheet.java:163)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:296)
        at com.zaxis.tm.utils.ExcelParser.readXldata(ExcelParser.java:84)
        at com.zaxis.tm.action.UploadFile.execute(UploadFile.java:231)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
        at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
        at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
        at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
        at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
        at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
        at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
        at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
        at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
        at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
        at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

我遇到问题的方法是

public boolean readXldata(String path,UpdateBean term) {

    logger.info("%%%%%%%%%%%%%%%% Inside Reading Export main Fle %%%%%%%%%%%%%%%%");


    ExportBean video = null;
    HSSFRow myRow = null;
    boolean status = false;
    ProcessMethods methds = new ProcessMethods();
    try{


        if(myFileSystem == null){
           myFileSystem = new NPOIFSFileSystem(new File(path));
        }
        if (myWorkBook == null){
           myWorkBook = new  HSSFWorkbook(myFileSystem.getRoot(),true);
        }
        if (mySheet == null){
            mySheet = myWorkBook.getSheetAt(0);
        }
        if(mySheet.isColumnHidden(2)){

            mySheet.setColumnHidden(2, false);
        }
       Iterator rowIter = mySheet.rowIterator();

       int start = term.getStart_index();

       logger.info("TARGET LANG START INDEX ::" +start+ "LAST INDEX ::" +term.getEnd_index());


       while(rowIter.hasNext()){



            flag = 0;
            myRow = (HSSFRow) rowIter.next();
            int id = 0;

            try{
                id = new Double(myRow.getCell(0).toString().trim()).intValue();
                logger.info("ID ::" +myRow.getCell(0));

            }catch(NumberFormatException nex){
                logger.info("\nNUMBER FORMAT EXCEPTION WHIILE READING CONTENT ENTRY IN FILE ::");
                continue;
            }

            }else{
                 logger.info("\nNUMBER FORMAT EXCEPTION WHIILE READING CONTENT ENTRY IN FILE ::");
                continue;
            }

            video = new ExportBean();

            video.setConcept(id);



            int Rownum =myRow.getRowNum();
            video.setRowno_ex(Rownum);

            int LastRow = mySheet.getPhysicalNumberOfRows() - 7 ;




             if(myRow.getCell(1)!=null && !myRow.getCell(1).toString().equals("")){
                video.setEntryclass(myRow.getCell(1).toString().trim());

            }







            flag=0;
            logger.info("LAST ROW NUMBER ::" +LastRow+" ROW NUMBER  ::" +Rownum+ "FLAG ::" +flag);

            if(term.getEnglish_term().equalsIgnoreCase(video.getEng_term())){
               flag = 1;


              if(!term.getTarget_term().equalsIgnoreCase(video.getTar_term())){

                  logger.info("Termlist English term is same to Export main  english term");
                  logger.info("Termlist English term" +term.getTarget_term()+" is not same to Export main  english term");

                  if(this.Update_Row(video,term)){

                      logger.info(" ############ ROW  NO::"+ video.getRowno_ex() + "SUCCESSFULLY UPDATED #######");
                      status = true;
                      return status;
                                                 }else{
                      logger.info(" ############  UPDATION FAILED  #########");
                      return status;
                                                      }

              }

            }else if (LastRow == Rownum && flag == 0){

                  logger.info("Reached to end of the row");

                 if(Insert_Row(video,term)){
                     logger.info("Insertion done successfully at row "+ mySheet.getLastRowNum());

                     return status=true;

                 }else{
                    logger.info("Failed to insert values at the last row");
                    return status;

                 }
              }

              logger.info("Termlist Eng term  is not same to main term " +video.getEng_term()+ " Continue with the process.......");

             continue;

        }

     myFileSystem.close();



    } catch (Exception e) {
        e.printStackTrace();
    }

    return status;
}

1 个答案:

答案 0 :(得分:2)

超出GC开销限制意味着JVM花费太多时间进行垃圾收集,这通常意味着您没有足够的内存。 所以你可能有内存泄漏,你应该启动jconsole或jprofiler并将它连接到你的jboss并在它运行时监视内存使用情况。

还可以帮助解决此问题的方法是暂时将内存(Xmx)增加到可以节省的时间。因为如果你可以延迟内存不足,你将有更多时间找到潜在的泄漏