JodConverter handle multiple request for converting documents

1k views Asked by At

My Java web application installed in server 2008. Basically application convert doc files to pdf using jodCOnverter library (using openoffice service). i am using following code to convert document.

  String OpenOfficeConnString="C:\\Program Files (x86)\\OpenOffice 4\\program\\soffice.exe -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\" -nofirststartwizard";
    Runtime rt = Runtime.getRuntime();
    Process pSoffice = rt.exec(OpenOfficeConnString); 

    File inputFile = srcDoc;

    String destDoc = srcDoc.getAbsolutePath().substring(0,
                        srcDoc.getAbsolutePath().lastIndexOf("."))
                        + "." + outputFileExt;

    outputFile = new File(destDoc);

                // connect to an OpenOffice.org instance running on port 8100
    OpenOfficeConnection connection = new SocketOpenOfficeConnection(
                        8100);
    connection.connect();

                // convert
    DocumentConverter converter = new OpenOfficeDocumentConverter(
                        connection);
    converter.convert(inputFile, outputFile);

                // close the connection
   connection.disconnect();

When there is single request document convert successfully.

But when multiple users try to convert document at same time it fire an error :

Error something like this:

com.artofsolving.jodconverter.openoffice.connection.abstractopenofficeconnection disposing info disconnected 

My question is how can i handle multiple request so every one can convert their documents without fetching any problem.

1

There are 1 answers

1
sockmonk On

One way would be for your web application to just add each incoming document to some sort of queue service (like Gearman or Beanstalkd for instance), and run one queue worker that does the conversions one at a time. This way the conversions will be done asynchronously, without a web app instance having to wait.

The web application could use long polling from the browser to see if the document is converted yet, or just ask your users to refresh the web page now and then to see whether it's been converted.