开发者

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

What is the experience of working with OpenOffice in server mode? I know OpenOffice is not multit开发者_JS百科hreaded and now I need to use its services in our server.

What can I do to overcome this problem?

I'm using 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:

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"));


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.


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.


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜