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

前端 未结 6 1296
孤街浪徒
孤街浪徒 2020-12-04 20:13

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

6条回答
  •  余生分开走
    2020-12-04 20:41

    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.

提交回复
热议问题