I’m new to Camunda and struggle with some basic concepts…
I’ve a very simple process definition: a service task polls for new data and spawns up a second process synchronously via startProcessInstanceByMessage. After that spawned process terminates and returns, polling for new data starts again. That simple process (which does the polling) is started by startProcessInstanceByKey.
Here’s the workflow:
The problem I have with that simple process is that after approximately five minutes, a second thread is spawned up which does the same polling in parallel. After a few minutes, a third thread is spawned which again does the polling.
I found out that I can control the number of threads spawned via configuration, but that cannot be the real fix So what am I missing / doing wrong?
Are you using asyncafter=true on the start event? If so, it could be that the job executor is starting a new thread every 5 minutes, because the inital job thread never actually relinquishes control as its in an endless loop. The job executore holds a lease on a job for 5 minutes (default). If the job is not complete, the executor assumes the thread crashed and thus attempts to process with a new thread…
An alternate approach could be to use a timer start event to regularly poll rather than a loop…
Actually asyncbefore was checked. Your explaination makes sense, now I’ve got a slightly better understanding of the mechanics behind it. Thank you very much!
The timer start event sounds helpful, could ease some unit testing issues regarding timeouts
Do you know where the lease of the job executor is configurable? Is it lockTimeInMillis from https://docs.camunda.org/manual/7.4/reference/deployment-descriptors/tags/job-executor/#job-acquisition-configuration-properties ?
Yes lockTimeMillis is the configuration of the duration of the lock…
@Webcyberrob: I tried to actually set the lockTimeMillis, but I could not find a way to do so in my Spring Boot application.
For thread pool sizes this can be done via application.properties:
camunda.bpm.job-execution.core-pool-size = 3
camunda.bpm.job-execution.max-pool-size = 10
But regarding the lockTimeInMillis I couldn’t find anytihng. I tried to configure it via processes.xml, but could not find an appropriate node there.
Do you have an idea where I can set this?
The real question is why would you want to change this?
If there’s a job execution which takes longer than 5 minutes, Camunda should not think there was a problem with the execution. At the moment, my jobs will definitively run within a few seconds, but I can imagine that in near future there might be jobs taking a couple of minutes.
Edit: I managed to set the value programmatically by providing a bean that implements AbstractCamundaConfiguration::preInit method. This way I could introduce a variable in application.properties. But I’m sure you have a reason for asking what I really want so that I actually should not have this problem.
If you have tasks which are potentially long running, you may want to consider using the external task pattern. From my perspective, tying up job executor threads in long running processing is not best practice and may lead to undesirable side effects.
Ok, thank you! I’ll read into it!
Do you have any hints on good primers on Camunda or do you suggest digging through the official documentation from start to beginning?