本文介绍了Ghost4J本机库可将pdf转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

在我同步使用此库之后,线程的性能不佳.即4个线程和8个线程,其性能没有差异.

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.

有什么安全的方法吗?

推荐答案

您是否尝试过ghost4j人们对多线程的建议:

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

确保Ghostscript是线程安全的第一步.但是,如果要在多线程/多用户环境(例如在Webapp中)中使用Ghost4J,该怎么办?

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)?

如果使用Ghost4J编写文档转换Web应用程序,那么如果用户必须等待上一个用户请求完成,则使用单个Ghostscript解释器可能是一个真正的问题.

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.

要克服此限制,Ghost4J在其高级API组件(版本0.4.0起)提供多线程支持.

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

这怎么可能? :组件处理在不同的JVM中进行.

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

主JVM中的组件能够启动其他JVM(在其他系统进程中运行)并使用cajo库(嵌入在ghost4j JAR文件中)控制它们.

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).

要确保可以从主JVM创建从属JVM,请检查是否可以使用java命令从命令行启动Java.

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.

可以通过在组件上设置maxProcessCount属性(如果有)来控制多线程行为:

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

  • 当= 0时:禁用多线程.组件将必须等待Ghostscript解释器获得免费才能开始对其进行处理.

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

当> 0时:启用多线程.组件处理不会在主JVM中进行,而是在从JVM中进行.给maxProcessCount赋予的值指示该组件可以同时运行多少个从属JVM.当达到最大数量的从属JVM时,新的处理请求将等待另一个处理完成.

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.

以下是设置PDFConverter组件以允许具有2个从属JVM的多线程的方法:

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本机库可将pdf转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 16:57