05-22-2017 04:29 AM
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?
05-23-2017 04:21 PM
> 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)
05-22-2017 11:23 AM
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
05-23-2017 10:30 AM
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
05-23-2017 01:04 PM
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
05-23-2017 04:21 PM
> 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)
Explore our Alfresco products with the links below. Use labels to filter content by product module.