Priyan at Dialog
Priyan at Dialog

Reputation: 319

Appropriate place in catalina.bat to set JAVA_OPTS

I got the below error

"java.lang.OutOfMemoryError: PermGen space"

In my catalina.bat file, where is the appropriate place for enter set JAVA_OPTS parameter? Bottom of the file or any other place?

Upvotes: 7

Views: 54420

Answers (5)

dan
dan

Reputation: 13272

Like others have already suggested you need to use JAVA_OPTS set to something like: JAVA_OPTS="-XX:MaxPermSize=98m". This, alone, will probably solve the issues, but if you are redeploying a lot of times and your war/jar is huge you will hit this memory limit too.

For this last scenario, something normal on a test/devel machines, I recommend using:

-XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC

This options will enable the unloading of the unused classes.

Look here more details, especially the comments.

Upvotes: 5

nos
nos

Reputation: 229342

The proper place is to create a new file in the Tomcat /bin directory alongside catalina.bat, named setenv.bat and place a set JAVA_OPTS=... there.

On *nix system it'd be setenv.sh

catalina.bat/catalina.sh takes care of running setenv.bat/setenv.sh if it exists. This is noted in the section 3.4 here

Upvotes: 5

Yogendra Singh
Yogendra Singh

Reputation: 34397

Please read this: OutOfMemory Error and make sure your application doesn't have memory leak and excessive memory usage.

To change the settings, create a file named setenv.bat for windows or setenv.sh for Linux with entry as below:

Windows:

set JAVA_OPTS="-Xms256m -Xmx512m"

Linux:

export JAVA_OPTS="-Xms256m -Xmx512m"

Simply put this(setenv.bat/setenv.sh) file in %CATALINA_HOME%\bin\ folder. Your command file (catalina.bat/catalina.sh) already has a statement as below:

Windows:

  if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"

Linux:

  if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
     . "$CATALINA_BASE/bin/setenv.sh"
  elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
     . "$CATALINA_HOME/bin/setenv.sh"
  fi

This will take care the rest.

Upvotes: 31

Lucas
Lucas

Reputation: 14979

In your environment. Our you could create a wrapper script that sets JAVA_OPTS then calls the catalina script.

Upvotes: 1

duffymo
duffymo

Reputation: 309008

This happened because you redeployed several times. You can increase your perm gen space, but it'll only delay the inevitable error.

You'll just have to restart your server. I'm not aware of a workaround.

Upvotes: 1

Related Questions