Script Task within a loop causing StackOverflowError

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member

Script Task within a loop causing StackOverflowError

We have a simple script task in a BPMN that is within a loop that is designed to loop around 500 times. The script task simply creates a string variable. We can see when we don't mark the script as asynchronous, we see a StackOverflowError after around 30 loops occur. If we mark it as asynchronous, we do not see the error.

Is there any indication why this occurs specifically with script tasks and not with any other tasks such as service tasks?

5 Replies
Senior Member

Re: Script Task within a loop causing StackOverflowError

After writing the recursive logic, the stack will be expanded, so StackOverflowError will occur.

How about increasing the thread stack size with JVM parameters?

-Xss:10m

-X Command-line Options

Highlighted
Active Member

Re: Script Task within a loop causing StackOverflowError

This is also something but we would need to be able to scale the stack if request and load increases on activiti, which is why I was wondering if there was something specific that only seems to cause it with script tasks in a loop, or indeed if there is an activiti element that can stop it occuring?

Highlighted
Senior Member

Re: Script Task within a loop causing StackOverflowError

Since the Xss option is related to the maximum value, I think the thread size will be expanded as necessary.

If we need to examin why the stack will be expanded, we need to check your script.

Highlighted
Active Member

Re: Script Task within a loop causing StackOverflowError

Makes sense. The script was simply creating an integer variable and adding 1 to it, but it is possible it can run thousands of times due it it being in a loop.

Highlighted
Senior Member

Re: Script Task within a loop causing StackOverflowError

Well, please upload the reproduction code (>_<) if you wanto to resolve this problem.