Enable One process instance at time

I wanted to create a process that turns periodically (every 1S for exemple), that prevents multiple instances from running at the same time:

  • Service Task “Verify One …”: created a service task which allows to calculate (in his delegate) the number of process instances that run.

-Gateway: if the number of process instances is greater than 0 then we finish the instance, otherwise we continue to the next service task

  • Task that taking time to be completed: within delegate of this task i put a Thread.sleep to simulate the time needed to complete it.

MY Objective: within “Verify One Process Instance At Time” check whether the task “Task taking time” is completed. otherwise, terminate the instance.

test case:

  • launch 4 instances (one instance each 1s)
  • in the “Task Taking Time” : set up a threed.sleep (4s)

Expected results:

  • “Task Taking Time” executed once and 3 instances rejected

Results obtained:

  • the 4 instances are all accessing the “Task Taking Time” task even though I have a threed

Does anyone know how to solve this problem please. I thank you in advance.

Take a look at: Limit number of concurrently running instances of a process definition

Thank you StephenOTT for your answer.

But I have already tried this solution. I noticed that when there are tasks that take time. then these process instances that turn on this task are not counted (when doing (…).processDefinitionKey (“competitorTest”). active (). count ())

Note that: I simulated a task that takes time using a Threed.sleep within his delegate or with a timer positioned after the task

do you know why my process instance is not counting even though it is running?

I thank you in advance

Set your timer start event to be a Async Before or Async After so that the start of the process instance is logged and the longer running work is a different transaction

I’m not completely sure I understand what you’re trying to do, but I think you’re trying to make sure that one and only one instance of a particular process is executing at a time. In other words, your parent process would check for the existence of an instance of that process and if it found it, it would not start another.

One crude way to do this is to query the REST API for current process instances and if the process in question is contain in the response, then you know not to start another. I’m sure there’s a more elegant way to do this through the Java model API. You could also directly query the database from a Java class or script.