pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "M. Niedermair" <m_...@gmx.de>
Subject Re: PDFont - thread save?
Date Fri, 09 Oct 2015 08:00:59 GMT

 > However, it is my personal experience that you can easily parallelize
> certain tasks calling pdfbox library methods using a miminal amount of care
> and design in the way you invoke and synchronize the threads.

I have now changed my code that the font is stored in a 
ByteArrayInputStream (So he does not need to be loaded every time.).
Then a separate PDFont is created for each task.

    private static ByteArrayFileInputStream libertine_R = null;

    public static PDFont getLibertine_R(final PDDocument document) 
throws IOException {
       if (libertine_R == null) {
          synchronized (FontLibertine.class) {
             if (libertine_R == null) {
                libertine_R = new ByteArrayFileInputStream(
       PDFont font;
       synchronized (libertine_R) {
          font = PDTrueTypeFont.loadTTF(document, libertine_R);
       return font;

The creation of PDFs is now 40 percent faster.

>     - Which framework do you use for your multi-threaded approach?

ThreadPoolExecutor and LinkedBlockingQueue<Runnable>

With the above solution I can work and create hundreds of PDFs in multi 

Thank you!

To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org

View raw message