In my java web application, I have one background workflow that requires a lot of stack space because it performs a very complex workflow using the workflow activiti mechanism and groovy script tasks.
Currently, I need to set the JVM Xss value to 16 MB in 64-bit Java and Tomcat to get around any StackOverflowErrors. If an error occurs, the stack trace is really huge (several hundred lines), but it all happens inside the engine, so I can not do anything about it.
Now my question is: is there a way to increase the stack size of a single thread at runtime?
I would like to lower the Jss default Xss settings for all threads in the application to 512 thousand, which, as far as I know, is enough, and only run the working one from 16 M.
The Java API provides some information on this for the constructor of the Thread class:
public Thread(ThreadGroup group, Runnable target, String name, long stackSize)
but he mentions that behavior is not guaranteed ([1]), and I did not find any information if it worked on windows.
Also, if the stack space of a single thread cannot be increased, and I must specify a value of 16 MB as the default value, what would be the consequences of such a high value? Does this mean that each new thread reserves 16 MB of memory during initialization (i.e. 200 threads * 16 MB: 3.2 GB)?
As far as I can tell from jconsole and taskmgr, the amount of memory doesn't seem to change much with the increase in Xss settings, but maybe I'm missing something.
Any help or clarification would be appreciated.
[1]: http://docs.oracle.com/javase/6/docs/api/java/lang/Thread.html#Thread(java.lang.ThreadGroup , java.lang.Runnable, java.lang.String, long)