Async Job Executor only executes job after lock expiration

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member

Async Job Executor only executes job after lock expiration

Hi

We are currently in the process of upgrading our Activiti deployment from version 6.18 to version 6.0, which includes also the new Async Job executor. While giving activiti 6 a try, I noticed something which I could not explain:

The documentation says, that if the asyncExecutor for a process engine is enabled, it would insert a job into the ACT_RU_JOB table and instantly lock it, and then dispatch it to the job executor running in the same process engine. I've observed that it creates the table row in ACT_RU_JOB with a lock, but then it doesn't execute it for a reason I cannot understand. As soon as the lock expires, the job executor of this engine aquires the job and executes it, but I expect that to happen immediately after inserting the Job into ACT_RU_JOB. Another interesting fact: This is not always the case, there are instances that run through immediately, as I would expect. I've also not saturated the engine, I've observed that behavior when there was no load at all.

We are using PostgreSQL as activiti database.

Here my process instance configuration:


    <bean id="executorProcessEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
        <property name="dataSource" ref="dataSource" />
        <property name="transactionManager" ref="transactionManager" />
        <property name="databaseSchemaUpdate" value="true" />
        <property name="asyncExecutorActivate" value="true" />
        <property name="asyncExecutorThreadPoolQueueSize" value="100" />
        <property name="asyncExecutorMaxPoolSize" value="50" />
        <property name="asyncExecutorNumberOfRetries" value="3" />
        <property name="asyncExecutorMaxAsyncJobsDuePerAcquisition" value="1" />
        <property name="asyncExecutorDefaultAsyncJobAcquireWaitTime" value="2000" />
        <property name="asyncExecutorDefaultTimerJobAcquireWaitTime" value="2000" />
        <property name="eventListeners">
            <list>
                <bean class="..." />
                <bean class="..." />
            </list>
        </property>
    </bean>

Has anybody seen this?

Any help is appreciated.

Regards, Jürg

5 Replies
Highlighted
Member II

Re: Async Job Executor only executes job after lock expiration

I have had similar experience with 5.22 we use. Seems the asyncExecutorDefaultAsyncJobAcquireWaitTime config does not apply on asyncExecutor. I tried to check config.getAsyncExecutor().getDefaultAsyncJobAcquireWaitTimeInMillis() it still returns default value (10 sec) even though I set it to 2 sec. Any how, i then set it by config.getAsyncExecutor().setDefaultAsyncJobAcquireWaitTimeInMillis(2000) on startup of my application and it works. That said I yet to figure out why it would not take initial config from asyncExecutorDefaultAsyncJobAcquireWaitTime. I use spring boot version and tried to set it by processEngineConfigurationConfigurer. Hope this helps Smiley Happy

Highlighted
Active Member

Re: Async Job Executor only executes job after lock expiration

Hi Kamlesh

Thanks for your reply, but unfortunately this does not seem to help. I've configured the defaultASsyncJobAcquireWaitTimeInMillis parameter during the initialisation of my Spring Boot Application, but it does not seem to help. I've noticed something interesting though. It does not happen if I have two process engines, one which creates the jobs (Async Executor Disabled), and the other one executing them (Async Executor Enabled). But still, this is really strange.

Unfortunately, the rest api from where some of my workflows are launched ties itself to the executor and not the producer engine. Does anybody how I can tie the rest api to a particular workflow engine when using Spring Boot? I've marked the producerProcessEngine as primary, but that does not seem to help:

    <bean id="producerProcessEngine" class="org.activiti.spring.ProcessEngineFactoryBean" primary="true">
        <property name="processEngineConfiguration" ref="producerProcessEngineConfiguration" />
    </bean>
    
    <bean id="executorProcessEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
        <property name="processEngineConfiguration" ref="executorProcessEngineConfiguration" />
    </bean>

Thanks and regards,
Jürg

Highlighted
Active Member

Re: Async Job Executor only executes job after lock expiration

I experienced same, and opened a stackoverflow.

Highlighted
Active Member

Re: Async Job Executor only executes job after lock expiration

It seems I found a workaround to address the problem:
-Start the process in a transaction.

-Suspend the process in same transaction.

-Activate the process after transaction commit.

Implementation in spring environment:

String processInstanceId = runtimeService.startProcessInstanceByKey(processId, variableMap).getId();

runtimeService.suspendProcessInstanceById(processInstanceId);

transactionTool.afterCommit(() -> {
         runtimeService.activateProcessInstanceById(processInstanceId);
});

public class TransactionTool {

public void afterCommit(Runnable runnable) {
if (TransactionSynchronizationManager.isActualTransactionActive()) {
logger.trace("Transaction exists, registering runnable after commit.");
TransactionSynchronizationManager.registerSynchronization(
new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
logger.trace("Commit done, executing runnable.");
runnable.run();
}
});
} else {
logger.trace("Transaction not exists, executing runnable in-place.");
runnable.run();
}
}

}

Highlighted
Member II

Re: Async Job Executor only executes job after lock expiration

I've done some research and provided my findings as another answer to the StackOverflow thread mentioned above Tasks marked as 'Async' and not 'Exclusive' causes the issue