Problem with Multi-threading

By: Anthony - hwchan1
Problem with Multi-threading
2003-02-06 04:27
I'm developing a multi-threaded reporting engine based on JasperReports 0.4.3. When it receives a request, it creates a new thread, which calls JasperRunManager.runReportToPdfFile(), to generate a report. The reports share a single report template, which uses a non-system font.

It works fine when there is only a single reporting thread. When there are more than one thread running concurrently, there seems to be a synchronization problem with JRPdfExporter.exportReportToStream(). How can I avoid such problem?

Thanks for any suggestion. Here is the stack trace of the exception thrown:

ExceptionConverter: A file descriptor does not refer to an open file.
at Method)
at com.lowagie.text.pdf.TrueTypeFontSubSet.readLoca(Unknown Source)
at com.lowagie.text.pdf.TrueTypeFontSubSet.readLoca(Unknown Source)
at com.lowagie.text.pdf.TrueTypeFontSubSet.readLoca(Unknown Source)
at com.lowagie.text.pdf.TrueTypeFontSubSet.process(Unknown Source)
at com.lowagie.text.pdf.TrueTypeFontUnicode.writeFont(Unknown Source)
at com.lowagie.text.pdf.FontDetails.writeFont(Unknown Source)
at com.lowagie.text.pdf.PdfWriter.close(Unknown Source)
at com.lowagie.text.pdf.PdfDocument.close(Unknown Source)
at com.lowagie.text.Document.close(Unknown Source)
at dori.jasper.engine.export.JRPdfExporter.exportReportToStream( Code))
at dori.jasper.engine.export.JRPdfExporter.exportReport(
at dori.jasper.engine.JasperExportManager.exportReportToPdfFile(
at dori.jasper.engine.JasperRunManager.runReportToPdfFile(

By: elmar weber - elmar_weber
RE: Problem with Multi-threading
2003-02-06 04:47

sounds as if the currently report uses the file and the other cannot read it (even if the error message sounds different).

If that is the source of the problem i'd try the following:
each Thread creates a copy of the print template (the compiled jasper report) which is named with a unique id (so that there are no duplicates while threads are running) and uses that for the report filling. after the filling the Thread deletes the file.


By: Anthony - hwchan1
RE: Problem with Multi-threading
2003-02-06 20:43
Thanks for ur reply, Elmar. I've tried two things:

1. Duplicate the .jasper file. Running two threads concurrently, each thread using a different .jasper file. It still fails with the same error.

2. Removing the non-system font, which is a TTF Unicode font, from the template. It works then.

It seems the source of problem is the sharing of TTF file, which depends on native file operations. I'm running my report engine on AIX 4.3. I've also tested it with Windows, my dear, there's no such problem.

How could I avoid the problem, apart from moving to Windows, or staying away from the use of my own TTF files?

By: elmar weber - elmar_weber
RE: Problem with Multi-threading
2003-02-07 13:07

in general I wonder why the sharing of the jasper file is no problem but the sharing of the TTF file.
Afaik only read operations are used to generate the report (except of writing it to disk). And multiple read operations on a file should not be a problem (even in a AIX environment =).
May there be some kind of a lock (something like flock in linux)?

Beside of my questions, here some solutions:
1. If you use the font just in some static fields you may create images and use them instead of the ttf font.

If you use it for the whole report:
2. How about copying the ttf file also?
Set the path to the ttf file relative to the jasper file (in the same directory) and create for each thread a temporary directory which is unique and then copy ttf and japer file there, generate the report and delete all stuff.
These few file operations (an mkdir and a copy of 2 files from about 200 k max I suppose) should not be a big performance problem.

2002 JI Open Discussion's picture
Joined: Aug 10 2006 - 3:28am
Last seen: 16 years 10 months ago

0 Answers:

No answers yet