Neobye Posted April 15, 2021 Share Posted April 15, 2021 We try to fill the reports in a parallel mode to speed up the fill process.JasperReports allows to fill a a report with a list of objects (JRBeanCollectionDataSource), but the filling is done serial, even when you use JRThreadSubreportRunnerFactory.Therefore we try to use Java parallelStream.The trial setup is the following:public class MyReportManager{ JasperReport jasperReport; LocalJasperReportsContext context; public MyReportManager(InputStream theInputStream){ // single instance of JasperReport // jasperReport = (JasperReport) JRLoader.loadObject(theInputStream); // single instance of context // context = new LocalJasperReportsContext(DefaultJasperReportsContext.getInstance()); context.setClassLoader(getClass().getClassLoader()); } public parallelFill(List<MyReportData> myReportData){ // parallel fill process myReportData.parallelStream().forEach(data-> { JasperFillManager fillManager = JasperFillManager.getInstance(context); JasperPrint jasperPrint = fillManager.fill(report, data.getParams(), data.getDataSource()); data.setJasperPrint(jasperPrint); }); } ... }[/code] public class MyReportData{ Map<String, Object> params; JRDataSource dataSource; JasperPrint jasperPrint; public MyReportData(Map<String, Object> theParams, JRDataSource theDataSource){ params = theParams; dataSource = theDataSource; } public Map<String, Object> getParams(){ return params; } public JRDataSource getDataSource(){ return dataSource; } public JasperPrint getJasperPrint(){ return jasperPrint; } public void setJasperPrint(JasperPrint theJasperPrint){ jasperPrint = theJasperPrint; }}[/code] When we call the parallelFill with about 15000 ReportData, the process is working...most of the time, but not always.Sometimes we suddenly encounter an JRException:net.sf.jasperreport.engine.JRException: Byte data not found at: myStyle.jrtxat net.sf.jasperreports.repo.RepositoryUtil.getBytesFromLocation(ReporitoryUtil.java:210)at net.sf.jasperreports.engine.xml.JRXmlTemplateLoader.loadTemplate(JRXmlTemplateLoader.java:114)at net.sf.jasperreports.enginge.fill.JRFillReportTemplate.loadTemplate(JRFillReportTemplate.java:110)...[/code]It looks like it tries to load the style in every fill process.My Questions:is it possible to use parallel stream in conjunction with JasperFillManager? How do we achieve this?do I have to use a separate context for every fill process?why is the JasperStyleTemplate not loaded once in the JasperReport during it's load through JRLoader? regards Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now