cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti engine increases CPU usage and thread count.

mahesh_yadav
Champ in-the-making
Champ in-the-making
Here is the issue that I am facing.

I am using simple workflow with a script task and I am using below script task.
def x = 0
def y = 5

while ( y > 0 ) {
    x++
}
which makes the execution as infinite. I have script task as 'async'. Also the 'lockTimeInMillis' setting i set it to 120000(2 mins).

For above case when I start process the thread hangs in infinite loop and after 2 mins another thread is started to execute the same step and this continues further which increases thread count to 100 and CPU usage as 100%.

Fix done till now:

I dont want retry in my application so I have one class which implements org.activiti.engine.impl.interceptor.Command<Object>.execute() method and make retry count to 0 for that job ID. So I check the task information in my application and if it exist then I throw some exception which is caught by above class and it does not do retry. So the problem of high CPU and threads increasing reduced.

But still the first thread that has started the process waits. Is there a way by which I can kill that thread ?
2 REPLIES 2

jbarrez
Star Contributor
Star Contributor
Yes, the jobs will be locked for a certain amount of time, before they are can be picked up by other threads.

Solution for this 'problem': limit the thread pool or set the lock time very very high.
Or put a timeout on the threadpool.

But if your job is infite … it doesnt sound like there is a right solution. Nor is there a use case for it?

mahesh_yadav
Champ in-the-making
Champ in-the-making
Thanks for you response.

Actually I was able to resolve the infinite loop issue in script task. I followed below approach.

1) Persisted task entry in my db for first call and set name of thread (it is async thread from activiti).
2) The above thread hangs in script task.
3) When activiti retries, I check db if entry exist in my db then i know that this is internal retry and not the retry because of failure (as i already disabled exception retry by activiti).
4) In this case I get all thread and find the thread with the current step id and stop it. After this throw exception so that this thread also dies.