I. First, the OpenOffice process is closed for many reasons, most of which are file conversion failures, resulting in service crash.
For example, the file is too large and the character set is not recognized. Two Batch files are used to monitor the soffice.exe process. If no, restart the process,
OpenOffice. bat always starts and monitors the process. If not, run. bat @ echo off: looptasklist | find/I "soffice.exe" If % errorlevel % = 1 (call "run. bat ") Ping-N 6 127.0.0.1> nulgoto looprun. bat starts the OpenOffice service @ echo offc: cd c: \ Program Files (x86) \ OpenOffice 4 \ programsoffice-Headless-accept = "socket, host = 127.0.0.1, Port = 8100; URP; "-nofirststartwizardp:
2. There is no return value for the office PDF conversion method. If the conversion fails in some cases, you cannot determine whether the conversion is successful,
DocumentConverter converter = new OpenOfficeDocumentConverter( connection); converter.convert(inputFile, outputFile);
// This method does not return a value. If the conversion fails, the function becomes stuck. For example, the OpenOffice service fails or is disabled. Other reasons are unknown.
In the above case, the conversion time must be specified and must be returned within the specified time. If no return is returned, the conversion fails.
// Futruetask is required for execution at the specified time
Executorservice executor = executors. newsinglethreadexecutor (); futuretask <string> future = new futuretask <string> (New callable <string> () {// use the callable interface as the construction parameter Public String call () {Boolean c = covertopdf (doccover. tfilename); // The encapsulated conversion method, which can be considered as converter. convert (inputfile, outputfile); If (C = true) {return "1" ;}else {return "0" ;}// call method requires a return string }}); executor.exe cute (future); try {string result = Future. get (15000, timeunit. milliseconds); // sets the timeout execution time to 15 seconds. If (result. equals ("1") {// indicates that the execution is successful. Continue with the Code.} catch (interruptedexception e) {break;} catch (executionexception e) {break ;} catch (timeoutexception e) {system. out. println ("time-out"); // kill the process because you do not know why. The process will be automatically restarted because one or more processes are monitored, the next conversion runtime.getruntime(cmd.exe C ("taskkill/f/IM soffice.exe *"); break;} finally {
executor.shutdown(); }