简体   繁体   English

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

[英]How can I use OpenOffice in server mode as a multithreaded service?

What is the experience of working with OpenOffice in server mode?在服务器模式下使用OpenOffice是什么体验? I know OpenOffice is not multithreaded and now I need to use its services in our server.我知道 OpenOffice 不是多线程的,现在我需要在我们的服务器中使用它的服务。
What can I do to overcome this problem?我能做些什么来克服这个问题?

I'm using Java.我正在使用 Java。

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

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

om.start();

You can then us the library eg for converting documents without having to deal with the pool of OOo instances in the background:然后,您可以使用该库来转换文档,而无需在后台处理 OOo 实例池:

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

Yes, I am using OpenOffice as a document conversion server.是的,我使用 OpenOffice 作为文档转换服务器。

Unfortunately, the solution to your problem is to spawn a pool of OpenOffice processes.不幸的是,您的问题的解决方案是生成一个 OpenOffice 进程池。

The commons-pool branch of JODConverter (before it moved to code.google.com ) implemented this out-of-the-box for you. JODConverter 的commons-pool分支(在移至code.google.com之前)为您实现了这个开箱即用的功能。

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 .但是如果没有很多端口(足够几个),我们可以通过增加task queue timeout来提高性能这里是一个文档 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:还有一件事,我们决定不在每个转换过程中startstop officeManager 。最后,我通过这种方法解决了这个任务:

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.当需要转换时,我调用JODConverterconvertPDF It will be stopped only when application was down.它只会在应用程序关闭时停止。

OpenOffice can be used in headless mode, but it has not been built to handle a lot of requests in a stressfull production environment. OpenOffice 可以在无头模式下使用,但它还不能在压力很大的生产环境中处理大量请求。

Using OpenOffice in headless mode has several issues:在无头模式下使用 OpenOffice 有几个问题:

  • The process might die/become unavailable.该进程可能会终止/变得不可用。
  • There are several memory leaks issues.有几个 memory 泄漏问题。
  • 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.)打开几个 OpenOffice “worker”并没有像预期的那样扩展,需要一些调整才能真正拥有不同的打开过程(有几个 OpenOffice 副本、多个服务、在不同的用户下运行。)

As suggested, jodconverter can be used to access the OpenOffice process.如建议的那样,jodconverter 可用于访问 OpenOffice 进程。

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

you can try this:你可以试试这个:

http://www.jopendocument.org/ 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.它是一个基于开源 java 的库,允许您在不打开办公室的情况下处理打开的办公室文档,从而无需 OOserver。

Vlad is correct about having to run multiple instances of OpenOffice on different ports. Vlad 关于必须在不同端口上运行多个 OpenOffice 实例是正确的。

I'd just like to add that OpenOffice doesn't seem to be stable.我想补充一点,OpenOffice 似乎不稳定。 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.我们在生产环境中运行它的 10 个实例,并将代码设置为在第一次尝试失败时重试另一个实例。 This way when one of the OpenOffice servers crashes (or doesn't crash but doesn't respond either) production is not affected.这样,当其中一台 OpenOffice 服务器崩溃(或不崩溃但也不响应)时,生产不会受到影响。 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).由于每天重启服务器很痛苦,我们正在慢慢地将所有文档转换为JasperReports (有关详细信息,请参阅 iReport)。 I'm not sure how you're using the OpenOffice server;我不确定您是如何使用 OpenOffice 服务器的; we use it for mail merging (filling out forms for customers).我们将其用于邮件合并(为客户填写 forms)。 If you need to convert things to PDF, I'd recommend iText .如果您需要将内容转换为 PDF,我推荐iText

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM