How do I increase Groovy's JVM Heap Size?

16,215

Solution 1

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

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

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

Share:
16,215

Related videos on Youtube

jonalv
Author by

jonalv

Updated on September 10, 2020

Comments

  • jonalv
    jonalv over 3 years

    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?

Related