cancel
Showing results for 
Search instead for 
Did you mean: 

Java program won't terminate after ProcessEngines.destroy()

louis44
Champ in-the-making
Champ in-the-making
I have a Java class I am running with a main method like this:

    public static void main(String[] args) {
        ProcessEngineConfiguration engineConfig =
                ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg-file-job.xml");
        ProcessEngine engine = engineConfig.buildProcessEngine();

        System.out.println("getting here");
        ProcessEngines.destroy();
        System.out.println("getting there");

       // will not terminate
    }

The activiti.cfg-file-job.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd">

  <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
      <property name="jdbcUrl" value="jdbc:h2:file:activiti;DB_CLOSE_DELAY=1000" />
      <property name="jdbcDriver" value="org.h2.Driver" />
      <property name="jdbcUsername" value="sa" />
      <property name="jdbcPassword" value="" />

      <property name="databaseSchemaUpdate" value="true" />
      <!– use async executor –>
      <property name="jobExecutorActivate" value="false" />
      <property name="asyncExecutorEnabled" value="true" />
      <property name="asyncExecutorActivate" value="true" />

  </bean>
 
</beans>


My java program doesn't terminate. I assume this is because the job executor thread is still running. Is ProcessEngines.destroy() supposed to shut everything down or do I have to do that manually some other way?

5 REPLIES 5

vasile_dirla
Star Contributor
Star Contributor
Hi Louis,
now will terminate:
<java>
public static void main(String[] args) {
    ProcessEngineConfiguration engineConfig = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg-file-job.xml");

    ProcessEngines.init();

    ProcessEngine engine = engineConfig.buildProcessEngine();
    System.out.println("getting here");
    ProcessEngines.destroy();
    System.out.println("getting there");

    // now will terminate
  }
<java>

louis44
Champ in-the-making
Champ in-the-making
Interesting. Yes, your example does work. But why? Just because init() was called?

One side effect of this is that if I had a config file called activiti.cfg.xml, the call to ProcessEngines.init() would load that file and then later load the other activiti.cfg-file-job.xml. I end up getting what I want (the configuration in activiti.cfg-file-job.xml is used, but it seems a bit strange to load the other one first.

jbarrez
Star Contributor
Star Contributor
How long did you wait for the shutdown? The shutdown of the job executor can take up to a minute if it's busy.

vasile_dirla
Star Contributor
Star Contributor
The cause why shutdown was not working is because Processes.isInitialized was false.
This is set to true after the ProcessEngines class is initialized (for details you could have a look into the sources of this class.)

if you prefer to use ProcessEngines.destroy() then you have to call also ProcessEngines.init()
otherwise just create the ProcessEngine instace and call the close() method of it.
<java>
ProcessEngine engine = engineConfig.buildProcessEngine();
    System.out.println("getting here");
    engine.close();
    System.out.println("getting there");
</java>

because ProcessEngines.destroy() does exactly the same but for all the processEngines registered with it.

louis44
Champ in-the-making
Champ in-the-making
Thank you.