Remember an OfficeException

  pdf

Order

When using the jodconverter for pdf conversion, according to the default configuration, an error will be reported as soon as the request volume comes up “org.jodconverter.office.officeexception: noofficemanager available.”

abnormal

2017-06-27 17:39:03.136  INFO 8 --- [ProcessThread-0] o.j.office.ManagedOfficeProcess          : process forcibly terminated with code 81
2017-06-27 17:52:55.067  INFO 8 --- [ustom-tomcat-27] o.j.office.ManagedOfficeProcess          : Executing task 'Restart After Timeout'...
2017-06-27 17:52:55.067  INFO 8 --- [ProcessThread-0] org.jodconverter.office.OfficeProcess    : Trying to forcibly terminate process: 'host=127.0.0.1,port=2002,tcpNoDelay=1' (pid -2)
2017-06-27 17:52:55.069 ERROR 8 --- [ustom-tomcat-27] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.jodconverter.office.OfficeException: task did not complete within timeout] with root cause

java.util.concurrent.TimeoutException: null
    at java.util.concurrent.FutureTask.get(FutureTask.java:205) ~[na:1.8.0_131]
    at org.jodconverter.office.PooledOfficeManager.execute(PooledOfficeManager.java:161) ~[jodconverter-core-4.0.0-RELEASE.jar!/:4.0.0-RELEASE]
    at org.jodconverter.office.ProcessPoolOfficeManager.execute(ProcessPoolOfficeManager.java:117) ~[jodconverter-core-4.0.0-RELEASE.jar!/:4.0.0-RELEASE]
    at org.jodconverter.OfficeDocumentConverter.convert(OfficeDocumentConverter.java:130) ~[jodconverter-core-4.0.0-RELEASE.jar!/:4.0.0-RELEASE]
    at org.jodconverter.OfficeDocumentConverter.convert(OfficeDocumentConverter.java:103) ~[jodconverter-core-4.0.0-RELEASE.jar!/:4.0.0-RELEASE]
    at org.jodconverter.OfficeDocumentConverter.convert(OfficeDocumentConverter.java:84) ~[jodconverter-core-4.0.0-RELEASE.jar!/:4.0.0-RELEASE]
    
2017-06-27 17:52:55.072  INFO 8 --- [ProcessThread-0] o.j.office.ManagedOfficeProcess          : process forcibly terminated with code 81
2017-06-27 18:05:53.759 ERROR 8 --- [ustom-tomcat-25] c.g.b.pdf.controller.ConvertController   : failed conversion:  [15563b] to pdf; org.jodconverter.office.OfficeException: No office manager available.; input file: file4579207008092030803.
2017-06-27 18:05:53.762 ERROR 8 --- [ustom-tomcat-25] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [conversion failed] with root cause

org.jodconverter.office.OfficeException: No office manager available.
    at org.jodconverter.office.ProcessPoolOfficeManager.execute(ProcessPoolOfficeManager.java:115) ~[jodconverter-core-4.0.0-RELEASE.jar!/:4.0.0-RELEASE]
    at org.jodconverter.OfficeDocumentConverter.convert(OfficeDocumentConverter.java:130) ~[jodconverter-core-4.0.0-RELEASE.jar!/:4.0.0-RELEASE]
    at org.jodconverter.OfficeDocumentConverter.convert(OfficeDocumentConverter.java:103) ~[jodconverter-core-4.0.0-RELEASE.jar!/:4.0.0-RELEASE]
    at org.jodconverter.OfficeDocumentConverter.convert(OfficeDocumentConverter.java:84) ~[jodconverter-core-4.0.0-RELEASE.jar!/:4.0.0-RELEASE]

Source code

Parameter

jodconverter-core-4.0.0-RELEASE-sources.jar! /org/jodconverter/office/DefaultOfficeManagerBuilder.java

final int numInstances =
        connectionProtocol == OfficeConnectionProtocol.PIPE ? pipeNames.length : portNumbers.length;
    final UnoUrl[] unoUrls = new UnoUrl[numInstances];
    for (int i = 0; i < numInstances; i++) {
      unoUrls[i] =
          (connectionProtocol == OfficeConnectionProtocol.PIPE)
              ? UnoUrlUtils.pipe(pipeNames[i])
              : UnoUrlUtils.socket(portNumbers[i]);
    }

Constructor

 /** Constructs a new instance of the class with the specified settings. */
  public ProcessPoolOfficeManager(
      final UnoUrl[] unoUrls,
      final File officeHome,
      final File workingDir,
      final ProcessManager processManager,
      final String[] runAsArgs,
      final File templateProfileDir,
      final long retryTimeout,
      final long retryInterval,
      final boolean killExistingProcess,
      final long taskQueueTimeout,
      final long taskExecutionTimeout,
      final int maxTasksPerProcess) {

    this.taskQueueTimeout = taskQueueTimeout;
    pool = new ArrayBlockingQueue<>(unoUrls.length);
    pooledManagers = new PooledOfficeManager[unoUrls.length];
    for (int i = 0; i < unoUrls.length; i++) {
      final PooledOfficeManagerSettings settings =
          new PooledOfficeManagerSettings(unoUrls[i], officeHome, workingDir, processManager);
      settings.setRunAsArgs(runAsArgs);
      settings.setTemplateProfileDir(templateProfileDir);
      settings.setRetryTimeout(retryTimeout);
      settings.setRetryInterval(retryInterval);
      settings.setKillExistingProcess(killExistingProcess);
      settings.setTaskExecutionTimeout(taskExecutionTimeout);
      settings.setMaxTasksPerProcess(maxTasksPerProcess);
      pooledManagers[i] = new PooledOfficeManager(settings);
    }
    logger.debug(
        "ProcessManager implementation is '{}'", processManager.getClass().getSimpleName());
  }

Solve

jodconverter:
  enabled: true
  portNumbers: 2002,2003,2004,2005,2006
  maxTasksPerProcess: 1000
  taskQueueTimeout: 30

You can start more than one office by setting up more than one port.
The queue capacity can be increased by setting maxTasksPerProcess.