Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 multithreaded and now I need to use its services in our server.
What can I do to overcome this problem?

I'm using Java.

like image 922
user63898 Avatar asked Mar 09 '09 06:03

user63898


4 Answers

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")); 
like image 98
Bastian Spanneberg Avatar answered Oct 21 '22 10:10

Bastian Spanneberg


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.

like image 28
vladr Avatar answered Oct 21 '22 09:10

vladr


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.

like image 31
Ulug'bek Avatar answered Oct 21 '22 11:10

Ulug'bek


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

like image 41
Mercer Traieste Avatar answered Oct 21 '22 10:10

Mercer Traieste