Understanding parallel subprocess - number of threads

To understand the parallel Subprocess, I created simple flow.
Generate Numbers generates 1000 random integers in a List. Inside a subprocess, I added two tasks to modify numbers and created a log within each task in the subprocess. Log is like this:

LOGGER.info("Original: " + num + " new " + newNum + " thread " + execution.getVariable(“nrOfInstances”));

This is generated logs. I can understand the “nrOfInstances” is 1000, but why are they all running in one thread-3 ? In this case, how is it different from sequential subprocess?
Two subtasks are not using async process. Async tasks also use one thread, but just take much longer.

06-Sep-2020 13:21:54.267 INFO [pool-2-thread-3] com.camunda.demo.subprocess.Multiply.execute Original: 128 new 384 thread 1000
06-Sep-2020 13:21:54.267 INFO [pool-2-thread-3] com.camunda.demo.subprocess.Modular.execute Mo Original: 384 new 4 thread 1000
06-Sep-2020 13:21:54.287 INFO [pool-2-thread-3] com.camunda.demo.subprocess.Multiply.execute Original: 383 new 1149 thread 1000
06-Sep-2020 13:21:54.287 INFO [pool-2-thread-3] com.camunda.demo.subprocess.Modular.execute Mo Original: 1149 new 9 thread 1000
06-Sep-2020 13:21:54.305 INFO [pool-2-thread-3] com.camunda.demo.subprocess.Multiply.execute Original: 841 new 2523 thread 1000
06-Sep-2020 13:21:54.306 INFO [pool-2-thread-3] com.camunda.demo.subprocess.Modular.execute Mo Original: 2523 new 3 thread 1000
06-Sep-2020 13:21:54.325 INFO [pool-2-thread-3] com.camunda.demo.subprocess.Multiply.execute Original: 937 new 2811 thread 1000
06-Sep-2020 13:21:54.325 INFO [pool-2-thread-3] com.camunda.demo.subprocess.Modular.execute Mo Original: 2811 new 1 thread 1000

Set async on your sub process. You need the parallel activity be to run as a job if you want multiple threads

Thanks for a reply, but that doesn’t change a number of threads. I see only one thread “pool-2-thread-x”

Can you create another process and create a parallel gateway with multiple async tasks. Confirm you are seeing different threads pick up your jobs

Stephen, I believe that may work, but that requires a fixed number of parallel tasks branched from a parallel gateway. Also, my part of questions is about difference between parallel subprocess and sequential subprocess under this kind of behavior.

I am asking you to do the test so you can confirm that the parallel task execution in a parallel gateway context shows the different threads in your log output.

Hi, you need to set exclusive to false to see true parallel execution. Setting exclusive to false tells the engine you know what you are doing when it comes to parallel execution…

Regards

Rob

1 Like

set exclusive to false to see true parallel execution

Yes, setting “multi instance exclusive” or “task’s exclusive” to false creates multiple threads at least. Thank you.

tells the engine you know what you are doing when it comes to parallel execution

This statement was very interesting and I immediately see one thing: Lots of “OptimisticLockingException” with my case. Interesting. Thank you. It helped me to understand the subprocess better.

Hi,
I have SubProcess defined in my overall execution flow and Marked multi Instance Exclusive SELECTED or UNSELECTED does not have any effect.

Overall Parent workflow is about executing the Order. and ‘execute’ sub process executes one line item from the order. Expectation is that sub process will execute in parallel. However I see that One Thread is executing all the sub processes.

I have following defined for this Activity
CallActivityType: BPMN
Multi Instance:
Loop Cardinality : Empty
Collection - expression
ElementVariable a wrapper object
MultiInstance Async Before - NOT Selected.
MultiInstance Async After - NOT Selected.
Asynchronous Continuations:
Asynch Before - SELECTED
Async After - NOT Selected.
Exclusive: SELECTED. ( & UNSELECTED) Tried both.

What are the things I am missing here ? Help appreciated in advance.
Attached the screenshot.

@StephenOTT putting parallel gateway also behaving like sequential process, mean one after another and are not starting at same time.

Kindly check this thread ,what exactly I was asked about parallel gateway.
https://forum.camunda.io/t/cant-run-two-service-task-parallelly/42790/4