如何在服务器模式下将 OpenOffice 作为多线程服务使用?

发布于 2024-09-06 01:46:11 字数 189 浏览 3 评论 0原文

在服务器模式下使用 OpenOffice 是什么体验?我知道 OpenOffice 不是多线程的,现在我需要在我们的服务器中使用它的服务。
我可以做什么来克服这个问题?

我正在使用Java。

What is the experience of working with OpenOffice in server mode? I know OpenOffice is not multithreaded and now I need to use its services in our server.
What can I do to overcome this problem?

I'm using Java.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

怀念你的温柔 2024-09-13 01:46:11

使用当前版本的 JODConverter (3.0-SNAPSHOT),处理多个线程非常容易OOo 无头模式,因为该库现在支持启动多个实例并将它们保存在池中,只需在构建 OfficeManager 实例时提供多个端口号或命名管道即可:

final OfficeManager om = new DefaultOfficeManagerConfiguration()
  .setOfficeHome("/usr/lib/openoffice")
  .setPortNumbers(8100, 8101, 8102, 8103)
  .buildOfficeManager();

om.start();

然后,您可以使用该库来转换文档,而无需在后台处理 OOo 实例池:

OfficeDocumentConverter converter = new OfficeDocumentConverter(om);
converter.convert(new File("src/test/resources/test.odt"), new File("target/test.pdf"));

With the current version of JODConverter (3.0-SNAPSHOT), it's quite easy to handle multiple threads of OOo in headless-mode, as the library now supports starting up several instances and keeping them in a pool, by just providing several port numbers or named pipes when constructing a OfficeManager instance:

final OfficeManager om = new DefaultOfficeManagerConfiguration()
  .setOfficeHome("/usr/lib/openoffice")
  .setPortNumbers(8100, 8101, 8102, 8103)
  .buildOfficeManager();

om.start();

You can then us the library e.g. for converting documents without having to deal with the pool of OOo instances in the background:

OfficeDocumentConverter converter = new OfficeDocumentConverter(om);
converter.convert(new File("src/test/resources/test.odt"), new File("target/test.pdf"));
回忆那么伤 2024-09-13 01:46:11

是的,我使用 OpenOffice 作为文档转换服务器。

不幸的是,解决您的问题的方法是生成一个 OpenOffice 进程池。

commons-pool 分支JODConverter(在移至 code.google.com 之前)已为您实现了此开箱即用功能。

Yes, I am using OpenOffice as a document conversion server.

Unfortunately, the solution to your problem is to spawn a pool of OpenOffice processes.

The commons-pool branch of JODConverter (before it moved to code.google.com) implemented this out-of-the-box for you.

长发绾君心 2024-09-13 01:46:11

谢谢巴斯蒂安。根据巴斯蒂安的回答,我找到了另一种方法。打开多个端口,它提供创建多线程的访问。但是,如果没有很多端口(足够几个),我们可以通过增加任务队列超时来提高性能这里是文档。再说一遍,我们决定不在每个转换过程中startstopofficeManager。最后,我通过这种方法解决了这个任务:

public class JODConverter {

    private static volatile OfficeManager officeManager;
    private static volatile OfficeDocumentConverter converter;

    public static void startOfficeManager(){
        try {

            officeManager = new DefaultOfficeManagerConfiguration()
                    .setOfficeHome(new File('libre office home path'))
                    .setPortNumbers(8100, 8101, 8102, 8103, 8104 )  
                    .setTaskExecutionTimeout(600000L)    // for big files
                    .setTaskQueueTimeout(200000L)        // wait if all port were busy
                    .buildOfficeManager();
            officeManager.start();

            // 2) Create JODConverter converter
            converter = new OfficeDocumentConverter(officeManager);

        } catch (Throwable e){
            e.printStackTrace();
        }
    }

    public static void convertPDF(File inputFile, File outputFile) throws Throwable {

        converter.convert(inputFile, outputFile);
    }

    public static void stopOfficeManager(){
        officeManager.stop();
    }

}

当需要转换时,我调用JODConverterconvertPDF。仅当应用程序关闭时才会停止。

Thanks Bastian. I found another way, based on Bastian's answer. Opening several ports it provides access to create multithreads. But without many ports(enought several) we can improve performence by increase task queue timeout here is a documentation. And one thing again, we decided not to start and stop officeManager on each convertion process.At the end, I solved this task by this approach:

public class JODConverter {

    private static volatile OfficeManager officeManager;
    private static volatile OfficeDocumentConverter converter;

    public static void startOfficeManager(){
        try {

            officeManager = new DefaultOfficeManagerConfiguration()
                    .setOfficeHome(new File('libre office home path'))
                    .setPortNumbers(8100, 8101, 8102, 8103, 8104 )  
                    .setTaskExecutionTimeout(600000L)    // for big files
                    .setTaskQueueTimeout(200000L)        // wait if all port were busy
                    .buildOfficeManager();
            officeManager.start();

            // 2) Create JODConverter converter
            converter = new OfficeDocumentConverter(officeManager);

        } catch (Throwable e){
            e.printStackTrace();
        }
    }

    public static void convertPDF(File inputFile, File outputFile) throws Throwable {

        converter.convert(inputFile, outputFile);
    }

    public static void stopOfficeManager(){
        officeManager.stop();
    }

}

I call JODConverter's convertPDF when convertion is need. It will be stopped only when application was down.

娇纵 2024-09-13 01:46:11

OpenOffice 可以在无头模式下使用,但它还不能在压力很大的生产环境中处理大量请求。

在无头模式下使用 OpenOffice 存在几个问题:

  • 进程可能会终止/变得不可用。
  • 有几个内存泄漏问题。
  • 打开多个 OpenOffice“工作进程”无法按预期扩展,需要进行一些调整才能真正拥有不同的打开进程(具有多个 OpenOffice 副本、多个服务,在不同用户下运行)。

如建议的,jodconverter 可用于访问 OpenOffice 进程。

http://code.google.com/p/jodconverter/wiki/GettingStarted

OpenOffice can be used in headless mode, but it has not been built to handle a lot of requests in a stressfull production environment.

Using OpenOffice in headless mode has several issues:

  • The process might die/become unavailable.
  • There are several memory leaks issues.
  • Opening several OpenOffice "workers" does not scale as expected, and needs some tweaking to really have different open proccesses (having several OpenOffice copies, several services, running under different users.)

As suggested, jodconverter can be used to access the OpenOffice process.

http://code.google.com/p/jodconverter/wiki/GettingStarted

魂牵梦绕锁你心扉 2024-09-13 01:46:11

你可以试试这个:

http://www.jopendocument.org/

它是一个基于java的开源库,允许您无需打开 Office 即可处理打开的 Office 文档,从而无需 OOserver。

you can try this:

http://www.jopendocument.org/

its an opensource java based library that allows you to work with open office documents without open office, thus removing the need for the OOserver.

心碎的声音 2024-09-13 01:46:11

Vlad 关于必须在不同端口上运行多个 OpenOffice 实例的说法是正确的。

我想补充一点,OpenOffice 似乎不稳定。我们在生产环境中运行 10 个实例,并将代码设置为在第一次尝试失败时重试另一个实例。这样,当其中一台 OpenOffice 服务器崩溃(或未崩溃但也不响应)时,生产不会受到影响。由于每天重新启动服务器很痛苦,因此我们正在慢慢将所有文档转换为 JasperReports (详细信息请参阅 iReport)。我不确定您如何使用 OpenOffice 服务器;我们用它来邮件合并(为客户填写表格)。如果您需要将内容转换为 PDF,我建议您使用 iText

Vlad is correct about having to run multiple instances of OpenOffice on different ports.

I'd just like to add that OpenOffice doesn't seem to be stable. We run 10 instances of it in a production environment and set the code up to re-try with another instance if the first attempt fails. This way when one of the OpenOffice servers crashes (or doesn't crash but doesn't respond either) production is not affected. Since it's a pain to keep restarting the servers on a daily basis, we're slowly converting all our documents to JasperReports (see iReport for details). I'm not sure how you're using the OpenOffice server; we use it for mail merging (filling out forms for customers). If you need to convert things to PDF, I'd recommend iText.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文