How to control serviceTask execution

cancel
Showing results for 
Search instead for 
Did you mean: 
robdiana72
Member II

How to control serviceTask execution

Jump to solution

In Activiti, we have a need to control how jobs (serviceTasks) are executed. More specifically, we have some jobs that we want to limit to 2 concurrently, but other jobs may run 10 concurrently. All of these jobs are serviceTasks, no Timers or other async code. I have looked at the JobExecutor (and the Async version) but it seems to deal only with async code. How can I control this type of serviceTask execution?

1 Solution

Accepted Solutions
daisuke-yoshimo
Senior Member

Re: How to control serviceTask execution

Jump to solution

> There used to be a setJobExecutor method in the ProcessEngineConfigurationImpl class but it appears to be missing now.

・Synchronous Job Executor

You should override DefaultJobExecutor.class and setJobExecutor to ProcessEngineConfiguration.

ProcessEngineConfiguration.setJobExecutor(org.activiti.engine.impl.jobexecutor.JobExecutor jobExecutor)
https://www.activiti.org/javadocs/org/activiti/engine/ProcessEngineConfiguration.html#setJobExecutor...

・Async Job Executor
You should override DefaultAsyncJobExecutor.class and setAsyncExecutor to ProcessEngineConfiguration.

ProcessEngineConfiguration.setAsyncExecutor(org.activiti.engine.impl.asyncexecutor.AsyncExecutor asyncExecutor)

https://www.activiti.org/javadocs/org/activiti/engine/ProcessEngineConfiguration.html#setAsyncExecut...

View solution in original post

8 Replies
gdharley
Intermediate

Re: How to control serviceTask execution

Jump to solution

I don't believe this is something you will be able to control using the Job Executor parameters.

These are general parameters to manage your job pool and maximum number of concurrent jobs so you can manage your memory, threads and other JVM resources.

For the service tasks that are restricted to two concurrent executions, I believe you will need to handle these in a different way.

I would have the service task b a stand alone application that reached into the process engine to see if there are any jobs waiting (or alternatively have the process add a message to a queue and have the handler monitor the queue) . The handler will then execute the job and respond (say on a message bus). The message listener in the process can then pull the payload and move on.

This way the self contained handler can manage how many concurrent requests it handles. The approach also throttles execution such that all messages get handled in due course, but not necessarily immediately.

The Camunda engine (a fork of activiti) implements this pattern as what they call external tasks:

External Tasks | docs.camunda.org 

Hope this helps,
Greg

robdiana72
Member II

Re: How to control serviceTask execution

Jump to solution

Greg,

Thanks for the suggestion. I had been thinking about an option like this, so I am glad to see it as somewhat recommended.

I know the default JobExecutor does not handle this situation, and we are supposed to be able to supply a different one, but there is no documentation on that kind of thing. I would prefer to get to one solution instead of a solution per workflow.

Thanks.

Rob

gdharley
Intermediate

Re: How to control serviceTask execution

Jump to solution

Hi Robert,

Since the Async Job executor was introduced the ability to completely override the Job Executor seems to have gone away.
There used to be a setJobExecutor method in the ProcessEngineConfigurationImpl class but it appears to be missing now.

However, you can still overload the Job Handlers with your own implementation (which is likely all you need).

Custom Job handlers are registered against a given job type (e.g. ProcessEventJobHandler).

Hopefully this will give you what you need.

Greg

daisuke-yoshimo
Senior Member

Re: How to control serviceTask execution

Jump to solution

> There used to be a setJobExecutor method in the ProcessEngineConfigurationImpl class but it appears to be missing now.

・Synchronous Job Executor

You should override DefaultJobExecutor.class and setJobExecutor to ProcessEngineConfiguration.

ProcessEngineConfiguration.setJobExecutor(org.activiti.engine.impl.jobexecutor.JobExecutor jobExecutor)
https://www.activiti.org/javadocs/org/activiti/engine/ProcessEngineConfiguration.html#setJobExecutor...

・Async Job Executor
You should override DefaultAsyncJobExecutor.class and setAsyncExecutor to ProcessEngineConfiguration.

ProcessEngineConfiguration.setAsyncExecutor(org.activiti.engine.impl.asyncexecutor.AsyncExecutor asyncExecutor)

https://www.activiti.org/javadocs/org/activiti/engine/ProcessEngineConfiguration.html#setAsyncExecut...

gdharley
Intermediate

Re: How to control serviceTask execution

Jump to solution

There is no such method in the current ProcessEngineConfiguration classes.
Refer: Activiti/ProcessEngineConfiguration.java at master · Activiti/Activiti · GitHub 

And: Activiti/ProcessEngineConfigurationImpl.java at master · Activiti/Activiti · GitHub 

This method appears to have disappeared in version 5.14.

Greg

gdharley
Intermediate

Re: How to control serviceTask execution

Jump to solution

My apologies, when I grep'd my source I could not find this reference.

So as long as your configuration class extends ProcessEngineConfiguration you will have the ability to define a custom JobExecutor. Interesting that the Impl class doesnt include this method.

That said, as you can still plug your own Job Executor into the engine, take a look at the ManagedJobExecutor for an example of a custom module.

Greg

robdiana72
Member II

Re: How to control serviceTask execution

Jump to solution

Thanks to both of you for your help. I will be pursuing the custom JobExecutor to see if I can get that idea to work.