cancel
Showing results for 
Search instead for 
Did you mean: 

Process instance execution happening sequentially

pavlos
Champ in-the-making
Champ in-the-making
Hello,

I have a process definition containing a service task that takes a few seconds to run. For performance reasons, I would like to run several instances of this process in parallel. I start each process instance in a for loop:


        for (SomeEntity e : entities) {

            LOG.info("Processing: " + e.getId());
            Map<String, Object> processVariables = new HashMap<String, Object>();
            processVariables.put("entity", e);

            runtimeService.startProcessInstanceByKey(PROCESSKEY, processVariables);
   }

According to the user manual, each process instance should run in a seperate thread: "And jobs from other process instances are delegated to other threads and executed concurrently". However, I see them all running in the same thread. If I turn the long running service task's async attribute to true, the process instances do indeed execute in a parallel manner.

I am using activiti 5.10 embedded in my spring app with a pretty simple configuration. The jobExecutor is activated in its defaut configuration. Any hints what I am doing wrong?

Thank you,
Pavlos
2 REPLIES 2

webcyberrob
Champ in-the-making
Champ in-the-making
My understanding of what may be happening is if your process template is not explicitely tagged with asynchronous, then the process instance will execute to the first wait state in the process using the client thread. Hence in your case you may see that all the process instances start and execute in the context of the looping client thread and thus you will get serial execution.

From the user guide

"…If you trigger Activiti (i.e. start a process, complete a task, signal an execution), Activiti is going to advance in the process, until it reaches wait states on each active path of execution. More concretely speaking it performs a depth-first search through the process graph and returns if it has reached wait states on every branch of execution. A wait state is a task which is performed "later" which means that Activiti persists the current execution and waits to be triggered again. …"

Check out the section on asynchronous continuations in the user guide, there's a good diagram which will hopefully clarify.

R

pavlos
Champ in-the-making
Champ in-the-making
Thank you for your answer, webcyberrob. You're apparently right. Every process instance will be executed in its parent thread. Only the JobExecutor will start jobs in another thread and this will only happen, as you pointed out, if a wait state has been reached, a task has the async flag set to true or a timer event fires.

Greetings,
Pavlos