How do I increase Groovy's JVM Heap Size?

蓝咒 提交于 2019-11-27 05:58:47

问题


Some sources on the web claims that I should be able to give the -Xmx param to groovy but that just gives me java.io.FileNotFoundException when it can't find the -Xmx file. Other sources tell me to set some variable named JAVA_OPTS but how do I do that? And how do I know if it worked?


回答1:


$ export JAVA_OPTS="$JAVA_OPTS -Xmx64M"
$ groovy



回答2:


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



回答3:


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.



来源:https://stackoverflow.com/questions/5459317/how-do-i-increase-groovys-jvm-heap-size

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