You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by jl...@gi-bon.sk on 2014/03/31 16:26:39 UTC
Re: multi threaded rendering
hi,
i was using 1.8.4 in multithreaded environment too.
i was converting multiple pages to images in several threads (actually it
is a servlet that generates preview images of pages, so multiple images
are requested by browser at the same time) and it was not reliable.
occasionally some images were damaged, they looked like they were
unfinnished.
so i had to fix my code with couple of synchronizations.
Best regards
Ing. Juraj Lonc
From: Andreas Lehmkühler <an...@lehmi.de>
To: users@pdfbox.apache.org,
Date: 06. 01. 2014 11:53
Subject: Re: multi threaded rendering
Hi,
> alex@lanin.de hat am 5. Januar 2014 um 03:20 geschrieben:
>
>
>
> Hi all,
>
> first of all: yes I have read the FAQ. I know pdfbox is not thread safe.
:-)
> I'm trying to render parts of a larger pdf to a BufferedImage. e.g.
> pages 5, 7, 10, 52, 53
> However this is quite slow: My initial timing measurements show that
> opening a pdf takes about half a second and rendering a single page
> takes 0.8 - 2.5 seconds (Laptop; i7). So rendering e.g. 5 pages is 0.5
> + 5 * 1.5 = 8 seconds. I'm using loadNonSeq and
> RenderUtil.convertToImage(page). I've also tried to use
> drawer.drawPage directly without creating BufferedImages for each
> page, same result.
>
> Again, I know pdfbox is not thread safe. But anyway I had an idea to
> make it multi threaded: just open the document in each thread
> separately! So at least in theory we get: 0.5 (5 times simultaneously)
> + 2.5 (slowest page) = 3 seconds total which would be less than half
> the time required before.
OK, to open the pdf multiple times will eliminate the most obvious
not thread safe thing (multithreaded access to one file), but there are
other parts, like cached static values, which may be probelematic. But
these
are just guesses, in the end you have to give it a try. And, please let us
know
if you find something which could be refactored to be thread safe.
> I haven't tested this yet, but maybe someone has already done
> something like this?
We are using PDFBox in a multithreaded environment to display and print
pdfs. But the feature isn't a main use case so that the simultaneous usage
of PDFBox doesn't happened that often. Maybe we are just lucky ;-)
> Regards,
> Alex
BR
Andreas Lehmkühler