Ghost4J native library to convert pdf to image

删除回忆录丶 提交于 2019-12-08 13:35:11

问题


I am using Ghost4J Native library 32bit and 64bit dll files to convert my PDF to images. I need to use it with ThreadPoolExecutor i.e. multithreaded, but since its native, it crashes my JBoss too often.

After I synchronize the use of this library, The threads do not perform well. i.e. with 4 threads, and with 8 threads, its no difference in performance.

Is there any safe way of doing this?


回答1:


Have you tried what the ghost4j people recommend for multi-threading:

Multi-threading

Making sure the Ghostscript is thread safe is a first step. But what if Ghost4J is to be used in a multi-thread / multi-user environment (in a webapp for instance)?

If Ghost4J is used to write a document conversion webapp, using a single Ghostscript interpreter may be a real problem if users have to wait for a previous user request to complete.

To get over this limitation Ghost4J provides multi-threading support on its high level API components (since version 0.4.0).

How it is possible? : component processing takes place in different JVMs.

Components in the main JVM are able to start other JVMs (running in other system processes) and control them using the cajo library (embedded in the ghost4j JAR file).

To make sure slave JVMs can be created from the main JVM, check if Java can be launched from command line using the java command.

Multi-threading behavior can be controlled by setting the maxProcessCount property on a component (when available):

  • When = 0: multi-threading is disabled. Component will have to wait for the Ghostscript interpreter to get free before starting its processing.

  • When > 0: multi-threading is enabled. Component processing will not take place in the main JVM but in a slave JVM. The value given to maxProcessCount indicates how many slave JVMs can run concurrently for the component. When the max number of slave JVMs is reached, new processing requests will wait for another processing to complete.

Here is how a PDFConverter component is setup to allow multi-threading with 2 slave JVMs:

//create converter
PDFConverter converter = new PDFConverter();

//set multi-threading
converter.setMaxProcessCount(2);

(ghost4j - Thread safety and multi-threading)



来源:https://stackoverflow.com/questions/17674165/ghost4j-native-library-to-convert-pdf-to-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!