[
https://issues.apache.org/jira/browse/PDFBOX-3689?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15873262#comment-15873262
]
Tilman Hausherr commented on PDFBOX-3689:
-----------------------------------------
PageImageFactory is missing... I'm wondering whether PDDocument or PDPage
objects are shared across threads. And the best would be if you can reproduce
this in a simple way. Currently this is some code that is part of something
bigger. Why do you think that PDFBox is responsible?
> PDFBox Hanging when Rendering PDF
> ---------------------------------
>
> Key: PDFBOX-3689
> URL: https://issues.apache.org/jira/browse/PDFBOX-3689
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 2.0.4
> Reporter: Ryan Kimber
> Attachments: troubled-pdf.pdf
>
>
> I'm trying to render the attached file in a Docker container, using the
> oracle-java-8 image, rendering pages with {{PDFRenderer.renderImageWithDPI}}
> is hanging indefinitely (or at least, for a very long time).
> I'm experiencing the same symptoms as PDFBOX-3562, where the call to
> renderImageWithDPI never returns, and likewise, I'm using the java startup
> parameter: {{-Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider}}.
> We are executing the renderImageWithDPI asynchronously using Callables and a
> newWorkStealingPool Executor, with a thread count equal to the number of
> processors + 1.
> Interestingly, when this code and this PDF run in the debugger on my Mac,
> there's no problem.
> This is the code, which runs fine when only one thread is created. Note that
> our code is called when a message is received, but this could easily be a
> main method instead:
> {code:java}
> public class NewPdfTemplateQueueWorker
> {
> private ExecutorService executor =
> Executors.newWorkStealingPool(threadCt);
> private Scheduler scheduler = Schedulers.from(executor);
> @Override
> public void processRequest(BuildResourceRequest serviceRequest) throws
> PdfServiceException
> {
> //We're going to expect just one action.
> GenerateImagesAndMetaDataStep buildStep =
> (GenerateImagesAndMetaDataStep) serviceRequest.getBuildSteps().get(0);
> buildStep.setRequestId(serviceRequest.getRequestId());
> buildStep.setSessionId(serviceRequest.getSessionId());
> long stopwatch = System.currentTimeMillis();
> try {
> byte[] pdfBytes = buildStep.getPdfBytes();
> PdfInfo pdfInfo = PdfMetaDataFactory.buildPdfInfo(pdfBytes);
> log.warn("it took until " + (System.currentTimeMillis() -
> stopwatch) + "ms to build the pdf info");
> //Generate and publish each page image and thumbnails...
> ArrayList<Callable<Throwable>> callList = new
> ArrayList<Callable<Throwable>>();
> callList.add(new CallablePdfInfoPersister(serviceRequest,
> buildStep, pdfInfo));
> PageImageFactory imageFactory = new PageImageFactory(pdfBytes);
> for(int i = 0; i < pdfInfo.getNumberOfPages(); i++)
> {
> log.info("Adding callablePageImageGenerator for page #"+ (i +
> 1) + "...");
> callList.add(new CallablePageImageGenerator(buildStep,
> imageFactory, i));
> }
> boolean allSucceeded = true;
> Throwable firstError = null;
> List<Future<Throwable>> results = executor.invokeAll(callList);
> for(Future<Throwable> result : results) {
> if(result.get() != null) {
> allSucceeded = false;
> firstError = result.get();
> break;
> }
> }
> if(allSucceeded) log.warn("We have created the page images and
> PDF Info and written them to Google Storage");
> else throw new PdfServiceException("Error generating at least one
> page image", firstError);
> }
> catch(PdfServiceException pdfse)
> {
> log.error("PDFServiceException while processing request:", pdfse);
> tryToRespondWithError(serviceRequest, pdfse);
> }
> catch(IOException | InterruptedException | ExecutionException fce) {
> log.error(fce.getClass().getName() + " while processing
> request:", fce);
> throw new PdfServiceException("Unable to process new PDF template
> due to exception:", fce);
> }
> finally {
> stopwatch = System.currentTimeMillis() - stopwatch;
> log.warn("It took " + stopwatch + "ms to convert the PDF to data
> and images...");
> }
> }
> }
> public class CallablePageImageGenerator implements Callable<Throwable>
> {
> private static final Logger log =
> LogManager.getLogger(CallablePageImageGenerator.class.getName());
> private GenerateImagesAndMetaDataStep buildStep;
> private PageImageFactory pageImageFactory;
> private int pageIndex;
> public CallablePageImageGenerator(GenerateImagesAndMetaDataStep
> buildStep, PageImageFactory pageImageFactory, int pageIndex)
> {
> super();
> this.buildStep = buildStep;
> this.pageImageFactory = pageImageFactory;
> this.pageIndex = pageIndex;
> }
> public Throwable call() {
> try {
> long pageTime = System.currentTimeMillis();
> //This pageImageFactory.convertToPageImage function calls
> pdfRenderer.renderImageWithDPI(pdPage, 150)...
> PageImage pageImage =
> pageImageFactory.convertPageToImage(pageIndex, 150);
> log.warn("Page " + (pageIndex + 1) + " Images took " +
> (System.currentTimeMillis() - pageTime) + "ms to generate...");
> //publisher.publishMessage(RESPONSE_QUEUE, new
> PageImageResult("pageImageResult", serviceRequest.getRequestId(),
> serviceRequest.getSessionId(), pageImage));
> //Write to Google Cloud Storage, but don't bother writing
> anywhere else
>
> //CachingGoogleCloudStorageUtil.putPageImage(buildStep.getBucket(),
> buildStep.getFileFolder(), pageImage);
> log.warn("Page " + (pageIndex + 1) + " complete in " +
> (System.currentTimeMillis() - pageTime) + "ms");
> return null;
> }
> catch(IOException ioe)
> {
> log.error("IOException generating images for page " + (pageIndex
> + 1), ioe);
> return ioe;
> }
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]