Appropriate place in catalina.bat to set JAVA_OPTS

2020-02-26 09:58发布

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?

标签: java tomcat
5条回答
▲ chillily
2楼-- · 2020-02-26 10:05

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

查看更多
爷、活的狠高调
3楼-- · 2020-02-26 10:12

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.

查看更多
欢心
4楼-- · 2020-02-26 10:19

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.

查看更多
可以哭但决不认输i
5楼-- · 2020-02-26 10:24

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.

查看更多
等我变得足够好
6楼-- · 2020-02-26 10:27

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

查看更多
登录 后发表回答