Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to run a long running processor async and use it from same thread?
    primarykey
    data
    text
    <p>Basically, we have a class called OfficeManger which acts as a driver to connect to openoffice software, it needs to be connected all the time so we can use the converter to convert documents. We start the OpenOfficeProcess during the start of the web application, which starts fine. But looks like the executor which running in init() is on different thread and we couldn't able to get the running instance of OfficeManager. How to run in its own thread so that I can have this instance called from different class to use the converter method?</p> <pre><code> OfficeDocumentConverter converter = OpenOfficeProcessor.getInstance().getDocumentConverter(); converter.convert(inputFile, outputFile, pdf); </code></pre> <p>OpenOfficeProcessor</p> <pre><code>public class OpenOfficeProcessor { private static final OpenOfficeProcessor INSTANCE = new OpenOfficeProcessor(); static ExecutorService executor = Executors.newSingleThreadExecutor(); private final OfficeManager officeManager; private final OfficeDocumentConverter documentConverter; public OpenOfficeProcessor(){ DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration(); String homePath = ConfigurationManager.getApplicationProperty(ConfigurationManager.OPENOFFICE_HOME_PATH); if(homePath != null){ configuration.setOfficeHome(homePath); } else { LOG.error("OpenOffice.home.path is not set in the properties file"); new Throwable("Please set OPENOFFICE.HOME.PATH parameter in the properties file"); } String port = ConfigurationManager.getApplicationProperty(ConfigurationManager.OPENOFFICE_LISTENER_PORT); if( port != null){ configuration.setPortNumber(Integer.parseInt(port)); }else { LOG.error("openoffice.listener.port is not set in the properties file"); } String executionTimeout = ConfigurationManager.getApplicationProperty(ConfigurationManager.OPENOFFICE_EXECUTION_TIMEOUT); if(executionTimeout != null){ configuration.setTaskExecutionTimeout(Long.parseLong(executionTimeout)); } String pipeNames = ConfigurationManager.getApplicationProperty(ConfigurationManager.OPENOFFICE_PIPES_NAMES); if(ConfigurationManager.getApplicationProperty(ConfigurationManager.OPENOFFICE_PIPES_NAMES)!= null){ configuration.setPipeNames(pipeNames); } officeManager = configuration.buildOfficeManager(); documentConverter = new OfficeDocumentConverter(officeManager); } public static OpenOfficeProcessor getInstance() { return INSTANCE; } protected static void init() { LOG.debug("Starting the open office listener..."); executor.submit(new Callable(){ @Override public Object call() throws Exception { OpenOfficeProcessor.getInstance().officeManager.start(); return null; } }); } protected static void destroy() { LOG.debug("Stopping the open office listener..."); OpenOfficeProcessor.getInstance().officeManager.stop(); } public OfficeManager getOfficeManager() { return officeManager; } public OfficeDocumentConverter getDocumentConverter() { return documentConverter; } } </code></pre> <p>OfficeManager</p> <pre><code>public interface OfficeManager { void execute(OfficeTask task) throws OfficeException; void start() throws OfficeException; void stop() throws OfficeException; boolean isRunning(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload