How to create asynchronous service task

I am aware that there is a way to implement asynchronous tasks using custom queues, but I need to know how to make an asynchronous service task with Camunda’s built in feature. I couldn’t find tutorials related to that.

To make a service task asynchronous you need to tick the async before or async after boxes on the properties panel in design time.
That will force a commit to the database.

thanks.
I did try that but i keep getting below error:

Session #1 (user: SA) is waiting to lock PUBLIC.ACT_RU_JOB while locking PUBLIC.ACT_HI_ACTINST (exclusive)."; SQL statement:
delete from ACT_RU_JOB where ID_ = ? and REV_ = ? [40001-171]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:169)
at org.h2.message.DbException.get(DbException.java:146)
at org.h2.table.RegularTable.doLock(RegularTable.java:489)
at org.h2.table.RegularTable.lock(RegularTable.java:435)
at org.h2.command.dml.Delete.update(Delete.java:58)
at org.h2.command.CommandContainer.update(CommandContainer.java:75)
at org.h2.command.Command.executeUpdate(Command.java:230)
at org.h2.jdbc.JdbcPreparedStatement.execute(JdbcPreparedStatement.java:194)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:44)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:69)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:105)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:71)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:152)
… 18 more

Can you please point to a tutorial that covers this concept. More specifically i am looking for a tutorial that has delegate classes for each service task , i need to know what other configurations are required other than just ticking “async” check box.

Did you study these for the async feature:
https://docs.camunda.org/manual/7.8/user-guide/process-engine/transactions-in-processes/
https://docs.camunda.org/manual/7.8/user-guide/process-engine/the-job-executor/

Your error looks like a problem with database locks, could be related to your database and isolation level settings:
https://docs.camunda.org/manual/7.8/user-guide/process-engine/database/#isolation-level-configuration

3 Likes

Is it possible to achieve the same only via API, in service task implementation? We would like to use our own implementaion (subclass of AbstractBpmnActivityBehavior), which decides itself (depending on some metadata) if it works sync or async.

If it works sync it calls at the end of execute method statement

    leave(execution);

if it runs in async manner, it needs to enforce storing the process state to db. I am calling

    Context.getCommandContext().transactionContext.commit();

But I am not sure if it is enough?

you can find Video Tutorial here: https://youtu.be/MpueF6LllxE