Java program won't terminate after ProcessEngines.destroy()
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2015 01:22 AM
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?
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?
Labels:
- Labels:
-
Archive
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2015 02:36 PM
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>
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>
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2015 07:12 PM
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.
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.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2015 08:27 AM
How long did you wait for the shutdown? The shutdown of the job executor can take up to a minute if it's busy.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2015 08:40 AM
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.
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.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2015 12:57 PM
Thank you.
