Jasper报告在Java Application中第一次加载需要太长时间

时间:2014-11-06 14:14:25

标签: java jasper-reports

我使用jasper报告在我的java应用程序中生成发票和GRN,我使用以下类来填充数据

public class IReport extends JFrame {

    public IReport(String filename,HashMap parameter){

        super("View Report");
        try {
             DefaultJasperReportsContext context = DefaultJasperReportsContext.getInstance();
            JRPropertiesUtil.getInstance(context).setProperty("net.sf.jasperreports.xpath.executer.factory",
    "net.sf.jasperreports.engine.util.xml.JaxenXPathExecuterFactory");
            JasperPrint print = JasperFillManager.fillReport(filename, parameter, DatabaseService.getConnection());

            JRViewer viewer = new JRViewer(print);

            Container c = getContentPane();
            c.add(viewer);


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

        setExtendedState(MAXIMIZED_BOTH); 
        toFront();

        setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    }

}

我使用以下方法通过点击按钮解析必要的参数来调用报告。

private void printReport(String grnno) {
        HashMap param = new HashMap();
        param.put("grnno", grnno);
        param.put("header1", dilukz_inventory.DILUKZ_INVENTORY.owner.getHeader1());
        param.put("header2", dilukz_inventory.DILUKZ_INVENTORY.owner.getHeader2());
        param.put("address", dilukz_inventory.DILUKZ_INVENTORY.owner.getAddress());
        param.put("telephone", dilukz_inventory.DILUKZ_INVENTORY.owner.getContactno());

        IReport showme = new IReport("Reports/GRN.jasper", param);       
        showme.setVisible(true);

    }

但问题是,当我打开应用程序后第一次执行此操作时,加载报告需要很长时间,例如需要20到30秒。我该怎么做才能避免这种情况?请建议我离开。

0 个答案:

没有答案