How do I increase Groovy's JVM Heap Size?

ぐ巨炮叔叔 提交于 2019-11-28 11:06:51
$ export JAVA_OPTS="$JAVA_OPTS -Xmx64M"
$ groovy

UPDATED: Go to your Groovy home folder and go into the bin directory. In startGroovy.bat, you can set it from 128MB to 512MB like this:

...
@rem set GROOVY_OPTS="-Xmx128m"
set GROOVY_OPTS="-Xmx512m"
...

Found another way to do this on Windows without having to modify JAVA_OPTS, etc. Go to your Groovy home folder and go into the bin directory. If you are invoking Groovy by calling the groovy.bat file, if you look inside it, you'll see it in turn runs startGroovy.bat. In startGroovy.bat, in the last lines of the script, you'll find something like this:

@rem Execute Groovy
"%JAVA_EXE%" %JAVA_OPTS% -classpath "%STARTER_CLASSPATH%" %STARTER_MAIN_CLASS% --main %CLASS% --conf "%STARTER_CONF%" --classpath "%CP%" %CMD_LINE_ARGS%

Add the Xmx switch and memory you need allocated after %JAVA_OPTS% and before -classpath, so you have something like this:

@rem Execute Groovy
"%JAVA_EXE%" %JAVA_OPTS% -Xmx256M -classpath "%STARTER_CLASSPATH%" %STARTER_MAIN_CLASS% --main %CLASS% --conf "%STARTER_CONF%" --classpath "%CP%" %CMD_LINE_ARGS%

Now when you go to run Groovy, the -Xmx value will be the allocated memory it uses. Nice thing about this approach is that you don't need to re-load your env variables every time you want to change heap size and you have fine-grained control over what you're doing with the JVM that Groovy is utilizing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!