gpt4 book ai didi

java - Ghost4J native 库将 pdf 转换为图像

转载 作者:行者123 更新时间:2023-12-01 14:20:09 25 4
gpt4 key购买 nike

我正在使用 Ghost4J Native 库 32 位和 64 位 dll 文件将 PDF 转换为图像。我需要将它与 ThreadPoolExecutor 一起使用,即多线程,但由于它是 native 的,它经常使我的 JBoss 崩溃。

我同步该库的使用后,线程表现不佳。即 4 个线程和 8 个线程在性能上没有区别。

有什么安全的方法可以做到这一点吗?

最佳答案

您是否尝试过 Ghost4j 人们推荐的多线程:

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)

关于java - Ghost4J native 库将 pdf 转换为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17674165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com