开发者

How do I increase Groovy's JVM Heap Size?

开发者 https://www.devze.com 2023-02-20 01: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 sourc

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消