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 ?
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.