cancel
Showing results for 
Search instead for 
Did you mean: 

How to shutdown process engine when Application Server shuts

ruedesilva
Champ in-the-making
Champ in-the-making
Hi,

We have Activiti running in Weblogic and it starts when Weblogic server is started with code similar to below in a Weblogic startup class:

Context jndi = InitialContextHelper.getInitialContext(InitialContextHelper.TYPE_DATASOURCE);
            DataSource ds = (DataSource) jndi.lookup(DATASOURCE_JNDI.BILLPLEX_DATASOURCE_JNDI.jndi());
           
            ProcessEngineConfiguration pec = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
            pec.setDataSource(ds);
            pec.setTransactionsExternallyManaged(true);
            pec.setDatabaseSchemaUpdate("true");
            bpmEngine = pec.buildProcessEngine();

Now the Job Executor is also running and everything works fine. However is there away to safely shutdown Activiti when the server shuts down? i.e. We do not want to shutdown Weblogic when a job executor is running for example. Is there a way to signal Activiti to close/shutdown safely and then proceed with the server shut down only after Activiti is shutdown?

thanks,
Rue
11 REPLIES 11

jbarrez
Star Contributor
Star Contributor
Call the destroy method on the processEngine object

For example, in a Spring environment:

<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean" destroy-method="destroy">
   <property name="processEngineConfiguration" ref="processEngineConfiguration" />
  </bean>

ruedesilva
Champ in-the-making
Champ in-the-making
And this would only destroy after completing all currently running threads right? (Such as any jobs executing).

Also we would like to get a little bit more understanding on how the Job executors work, so that we can explain to customers.

1) Does Activiti create a new thread when the engine starts (i.e. buildProcessEngine)?
2) Does it matter for performance how many jobs we have in the DB running ?( i.e. is it one new thread per scheduled job?) Or there is just one thread that handles everything?
3) What is used for scheduling? A third-party app like Quartz or something built into Activiti?

thanks again,
Rue

frederikherema1
Star Contributor
Star Contributor
Yes, it tries to complete all running jobs (with a timeout)

1.Indeed, when "jobExecutorActive" property is set to true, the jobexecutor starts when the process-engine is built.
2. One thread is started that acquires the jobs. These job's are passed on to a thread-pool. The size can be altered using properties on the process-engine configuration. So performance is based on pool-size and your machine Smiley Wink
3. Scheduling of the timers is done in the JobExecutor itself. All jobs (including timers) are handled the same, aquired by the thread and handles by the thread-pool.

ruedesilva
Champ in-the-making
Champ in-the-making
Thanks for the answers. But I still have these:

2) Can you indicate what the properties I need to set are? Note that I am building the process engine in code. So I would need the API calls.

3) What mechanism is used for scheduling/ Your own code? Or a third party product like Quartz?

thanks, in advance,
Rue

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
3) Own, see the source, it is open  Smiley Wink

frederikherema1
Star Contributor
Star Contributor
Before starting the jobExecutor, you can set the properties (using Java) "maxPoolSize" and "corePoolSize".

anand0210
Champ in-the-making
Champ in-the-making
if we configure the below steps in Spring *.xml will it enough or do we need to be implement destory method even though it is already implemented in lib class.
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean" destroy-method="destroy">
   <property name="processEngineConfiguration" ref="processEngineConfiguration" />
  </bean>

testing: deploy in to server and run activity then shutdown server will this able to safe destroy?
please give me more details info along with examples on implementation.

jbarrez
Star Contributor
Star Contributor
> please give me more details info along with examples on implementation.

I'm not sure if I'm understanding what your asking here .. are you asking whether it's safe to use it like that? If so, yes.

anand0210
Champ in-the-making
Champ in-the-making
I am asking
1) how to do implementation and testing? if any snippets or  examples would help me to understand in detail.
2) how do we confirm it safe shutdown  when the process is running state? should process completes its task or not?

I did below steps please correct me if i am wrong:
———————————————-
started Actviti flow then stop the server when actviti  process completes few tasks and  yet to do more tasks.
I noticed that activiti process stops immediately and show the status as IN PROGRESS for the current tasks.
I wanted to know whether it stops activiti engine after it updates status as COMPLETED?

please share more information on how activiti engine behaves when server shutdown.

Thanks
Anand