Some generated reports are not filled with parameters

0

Hello,

Everything works smooth, when I'm not using threads in application, while calling jasper API to generate reports. But as I saw, if I will use java thread pools, I could generate reports much faster. Only one problem. When I use thread pools, some reports are generated  wrong - without parameters filled.
 

...
 
ExecutorService executor = Executors.newFixedThreadPool(5);
for(int i = 0; i < 1000; i++){
    Runnable runnable = new Generator(parameters, "target/resources/Invoice.jasper", "Invoice", i);
    executor.execute(runnable);
}
 
...
public class Generator implements Runnable {
...
 
@Override
public void run() {
    try {
        JasperPrint jp = JasperFillManager.fillReport(sourceFileName, params, new JREmptyDataSource());
        JasperExportManager.exportReportToPdfFile(jp, "./target/resources/" + printFileName + "-" + counter + ".pdf");
...

I know, that it can be related with subreprot filling, because these jasper API generating methods already working in multi-threading.
Maybe anyone can comment on that? Is it possible to ganerate a lot of reports while using executor pool?

Thanks,
TM

motiejunas.tadas's picture
Joined: Oct 25 2016 - 6:38am
Last seen: 3 years 2 months ago

1 Answer:

0

Looking at your code, it might be that you use the same parameters map object for all the reports.  That would be a problem, you need to create a fresh map for each fill process.

Regards,

Lucian

lucianc's picture
7174
Joined: Jul 17 2006 - 1:10am
Last seen: 1 day 6 hours ago
Feedback
randomness