Get count of number of running async jobs

Hi,

My usecase is to limit the number of jobs of same type(coming from same element in process) to run simultaneously so as to reduce load from background processing of one type of job.

To do this, I want to know the count of active running jobs at any time. ACT_RU_JOB table includes all the jobs to be picked up, but how do I find ones currently running? I am new to flowable, any pointers would help.

To know the jobs that are currently picked for execution or are being executed, you can call #getThreadPoolQueue() on the async executor. This is the BlockingQueue that backs the ExecutorService used by the async executor. On the Blockinqueue, you can then call for example #getRemainingCapacity() to know how full the queue currently is.

@joram Thanks for the response.

I want to find how many jobs belonging to a particular element_id are currently running. So threadPoolQueue will not be having this information. I tried like:

new JobQueryImpl().elementId(elementId).locked()

Above query gives count of all jobs that are being acquired by async executor. But all of it might not be picked up by it. This is because by default all the jobs are locked and is tried to execute. So even though my pool size is 30, this query would return all, say 100 async jobs are spawned new. Based on the state of records in ACT_RU_JOB is there a way to find if job is already running(not just acquired)?

This will get me to final goal of running only x number of jobs of a certain type at a time, controlling it. For a detail on what I am trying, please refer this. Any ideas would be useful.

Not immediately. All jobs get inserted in the table (some locked, some not, depending on the current load of that local async executor). So in theory, you could use something that keeps a watch on inserted rows. One option could be to use an event listener (like an entity created event listener) that stores, for each job that is created, a counter using the elementId.