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?
Solved! Go 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)
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
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
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
> 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)
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
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
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.
Ask for and offer help to other Alfresco Process Services and Activiti Users and members of the Alfresco team.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.