weixin_42297358 2008-10-16 23:54
浏览 261

关于JaserReport报表的应用导致tomcat无限占用内存问题

   最近启动tomcat时,用top查看内存占用为7%左右。2小时后为13%左右。4小时后为20%左右。8小时后内存用完,死机!这期间内存一直是上涨,没有下降过,即使一个晚上不连接不操作,第二天还是居高不下,没办法只好重启tomcat。



   我下载了个jProfiler来查看了下,那个类在占用着资源,发现这个net.sf.jasperreport.engine.fill包下的JRTemplatePrintText类,其Instance count不断增加,其占用的内存也不断上涨,我查看了代码,发现代码里面根本没有调用过此类(若有调用也是jasperreport内部机制调用的),代码如下:

    public static void getpdfreport(List data, String title, String year, String filereport,String pdfname,HttpServletResponse response, HttpServletRequest request){

try{

File reportFile = new File(request.getRealPath(filereport));

if (!reportFile.exists())

    System.out.println("文件不存在");

else

    System.out.println("文件存在");

        JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath());

    Map parameters = new HashMap();

    parameters.put("title", title);

    JRBeanCollectionDataSource ds=new JRBeanCollectionDataSource(data);      

    JasperPrint jasperPrint=JasperFillManager.fillReport(jasperReport, parameters,ds);

    response.setContentType("application/pdf");

    JRPdfExporter exporter=new JRPdfExporter();

    ByteArrayOutputStream baos=new ByteArrayOutputStream();

    exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "GB2312");

    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);

    exporter.exportReport();

    //以下为另打开文件

    byte[] bytes;

    bytes=baos.toByteArray(); 

    String newpdf="/report/"+pdfname;

    File pdffile = new File(request.getRealPath(newpdf));

FileOutputStream fos=new FileOutputStream(pdffile);

fos.write(bytes);

fos.close();

   }catch (JRException e){

   System.out.println("JRException出错:"+e.toString());

       e.printStackTrace();

  }catch (IOException ex) {

   System.out.println("IOException出错:"+ex.toString());

           ex.printStackTrace();

      }

    }

一旦调用了此方法net.sf.jasperreport.engine.fill.JRTemplatePrintText包就开始出现并曾现递增状况。



    系统在我本机的tomcat下跑的时候不会出现这种情况,但发布到公共服务器上供多人联网同时进行操作,这种情况就曾现出来了,一旦内存被盛满tomcat就会出现假死现象,系统将会特别慢,但是一直想不到解决方法,还希望大家能指点指点。

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?