Parallel fill with Java ParallelStream?


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());
    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());

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;

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.jrtx
at net.sf.jasperreports.repo.RepositoryUtil.getBytesFromLocation(
at net.sf.jasperreports.engine.xml.JRXmlTemplateLoader.loadTemplate(
at net.sf.jasperreports.enginge.fill.JRFillReportTemplate.loadTemplate(

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?


Neobye's picture
Joined: May 6 2013 - 6:01am
Last seen: 3 weeks 5 days ago

0 Answers:

No answers yet